Slide 1

Slide 1 text

Steve Miner @miner

Slide 2

Slide 2 text

edn-format.org edn is a system for the conveyance of values. It is not a type system, and has no schemas.

Slide 3

Slide 3 text

Schema the shape of data

Slide 4

Slide 4 text

Herbert a schema language for EDN

Slide 5

Slide 5 text

Whiteboard Compatible simple terse readable

Slide 6

Slide 6 text

EDN in EDN

Slide 7

Slide 7 text

Patterns • Literals - :kw, “foo”, 42, nil, true, false • Symbols - int, kw, str, sym, list, vec • Maps - {:a int} • Vectors - [int kw] • Operators - (or nil (and int (not 42))

Slide 8

Slide 8 text

Quantifiers • (? kw) • (* int) • (+ sym) • kw? int* sym+

Slide 9

Slide 9 text

{:a int :b? sym :c [str*]} matches: {:a 42 :b foo :c [“abc” “def”]} {:a 42 :c [“x” “y”]} {:a 42 :b foo :c []}

Slide 10

Slide 10 text

Grammar (grammar [person+] name (and str (not (pred clojure.string/blank?))) handle (str “@.+”) person {:first name :last name :twitter? handle}) ! [{:first “Steve” :last “Miner” :twitter “@miner”} {:first “James” :last “Kirk”}] ! (grammar (list 'grammar pattern (* term pattern)) term sym pattern any)

Slide 11

Slide 11 text

Bindings [(:= n int) n n] matches [3 3 3] {:a (:= s sym) :b (not s)} matches {:a foo :b bar} [(:= low int) (:= hi int) (int* low hi)] matches [3 7 4 6 5] ! {:len (:= n int) :vals (and (cnt n) [sym*])} matches {:len 5 :vals [a b c d e]}

Slide 12

Slide 12 text

Tags • (tag inst) matches any java.util.Date, java.util.Calendar and java.sql.Timestamp • (tag my.ns/Rec) matches any record my.ns.Rec • (tag my.ns/Rec {:a int}) matches #my.ns.Rec{:a 42} • protocol miner.tagged.EdnTag in tagged

Slide 13

Slide 13 text

Herbert API (conforms? pattern value) (conform pattern) (def my-test? (conform ‘[(:= k kw) sym+])) (my-test? ‘[:a foo bar baz]) ;=> {k :a}

Slide 14

Slide 14 text

Herbert • Open source on github and clojars • https://github.com/ miner/herbert • https://clojars.org/ com.velisco/herbert

Slide 15

Slide 15 text

Thanks • Eric Normand - squarepeg parser • tagged library - tagged records • edn-format.org • Prismatic schema • runa-dev clj-schema • http://tos.trekcore.com for Star Trek photos

Slide 16

Slide 16 text

Star Trek {:title “The Way to Eden” :stardate #tos/stardate 5832.3 :airdate #inst “1969-02-21” :season 3 :episode 20}

Slide 17

Slide 17 text

Steve Miner @miner

Slide 18

Slide 18 text

Examples • [kw str int] - [:a “foo” 4] • {:a int :b sym :c kw} - {:a 42 :b bar :c :baz} • (keys kw sym) - {:a foo :b bar :c baz} • [int+ kw?] - [1 2 3 :end]

Slide 19

Slide 19 text

Martin Fowler • “schemaless” means implicit schema • prefer explicit schemas • http://martinfowler.com/articles/schemaless/ • https://www.youtube.com/watch?v=8kotnF6hfd8

Slide 20

Slide 20 text

Uses for Schemata • Documentation • Validation • Pattern matching • Data transformation