diff options
author | Julien M'Poy <julien.mpoy@gmail.com> | 2017-11-08 13:29:24 +0100 |
---|---|---|
committer | Julien M'Poy <julien.mpoy@gmail.com> | 2017-11-08 13:29:24 +0100 |
commit | 5e81853768c0f3cc55c05e0dfec18773045df952 (patch) | |
tree | b62c3fb0bfc6de3318e962b330e163f3d65cdfa6 /edn.html.markdown | |
parent | 20893f5d83b4f7a1585bac9e7656d6af46183262 (diff) | |
parent | 6ce71c56d6affb57a3537a2732485a4918306d4b (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'edn.html.markdown')
-rw-r--r-- | edn.html.markdown | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/edn.html.markdown b/edn.html.markdown index 04346eb8..f47853f0 100644 --- a/edn.html.markdown +++ b/edn.html.markdown @@ -44,13 +44,13 @@ false :cheese :olives -; Symbols are used to represent identifiers. They start with #. +; Symbols are used to represent identifiers. ; You can namespace symbols by using /. Whatever precedes / is -; the namespace of the name. -#spoon -#kitchen/spoon ; not the same as #spoon -#kitchen/fork -#github/fork ; you can't eat with this +; the namespace of the symbol. +spoon +kitchen/spoon ; not the same as spoon +kitchen/fork +github/fork ; you can't eat with this ; Integers and floats 42 @@ -84,22 +84,26 @@ false #MyYelpClone/MenuItem {:name "eggs-benedict" :rating 10} -; Let me explain this with a clojure example. Suppose I want to transform that +; Let me explain this with a Clojure example. Suppose I want to transform that ; piece of EDN into a MenuItem record. (defrecord MenuItem [name rating]) -; To transform EDN to clojure values, I will need to use the built in EDN -; reader, edn/read-string +; defrecord defined, among other things, map->MenuItem which will take a map +; of field names (as keywords) to values and generate a user.MenuItem record -(edn/read-string "{:eggs 2 :butter 1 :flour 5}") +; To transform EDN to Clojure values, I will need to use the built-in EDN +; reader, clojure.edn/read-string + +(clojure.edn/read-string "{:eggs 2 :butter 1 :flour 5}") ; -> {:eggs 2 :butter 1 :flour 5} -; To transform tagged elements, define the reader function and pass a map -; that maps tags to reader functions to edn/read-string like so +; To transform tagged elements, pass to clojure.edn/read-string an option map +; with a :readers map that maps tag symbols to data-reader functions, like so -(edn/read-string {:readers {'MyYelpClone/MenuItem map->menu-item}} - "#MyYelpClone/MenuItem {:name \"eggs-benedict\" :rating 10}") +(clojure.edn/read-string + {:readers {'MyYelpClone/MenuItem map->MenuItem}} + "#MyYelpClone/MenuItem {:name \"eggs-benedict\" :rating 10}") ; -> #user.MenuItem{:name "eggs-benedict", :rating 10} ``` |