From e8b9f47ce4102217d16707d80d31a663e683f716 Mon Sep 17 00:00:00 2001 From: Jason Yeo Date: Tue, 20 Oct 2015 22:26:37 +0800 Subject: Add a short tutorial for edn --- edn.html.markdown | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 edn.html.markdown (limited to 'edn.html.markdown') diff --git a/edn.html.markdown b/edn.html.markdown new file mode 100644 index 00000000..b8dc4e88 --- /dev/null +++ b/edn.html.markdown @@ -0,0 +1,107 @@ +--- +language: edn +filename: learnedn.edn +contributors: + - ["Jason Yeo", "https://github.com/jsyeo"] +--- + +Extensible Data Notation or EDN for short is a format for serializing data. + +The notation is used internally by Clojure to represent programs and +it is used commonly by Clojure and Clojurescript programs to transfer +data. Though there are implementations of EDN for many other +languages. + +The main benefit of EDN is that it is extensible, which we will see +how it is extended later on. + +```Clojure +; Comments start with a semicolon. +; Anythng after the semicolon is ignored. + +;;;;;;;;;;;;;;;;;;; +;;; Basic Types ;;; +;;;;;;;;;;;;;;;;;;; + +nil ; or aka null + +; Booleans +true +false + +; Strings are enclosed in double quotes +"hungarian breakfast" +"farmer's cheesy omelette" + +; Characters are preceeded by backslashes +\g \r \a \c \e + +; Keywords starts with a colon. They behave like enums. Kinda +; like symbols in ruby land. + +:eggs +:cheese +:olives + +; Symbols are used to represent identifiers. You can namespace symbols by +; using /. Whatever preceeds / is the namespace of the name. +#spoon +#kitchen/spoon ; not the same as #spoon +#kitchen/fork +#github/fork ; you can't eat with this + +; Integers and floats +42 +3.14159 + +; Lists are a sequence of values +(:bun :beef-patty 9 "yum!") + +; Vectors allow random access +[:gelato 1 2 -2] + +; Maps are associative data structures that associates the key with its value +{:eggs 2 + :lemon-juice 3.5 + :butter 1} + +; You're not restricted to using keywords as keys +{[1 2 3 4] "tell the people what she wore", + [5 6 7 8] "the more you see the more you hate"} + +; You may use commas for readability. They are treated as whitespaces. + +; Sets are collections that contain unique elements. +#{:a :b 88 "huat"} + +;;; Tagged Elements + +; EDN can be extended by tagging elements with # symbols. + +#MyYelpClone/MenuItem {:name "eggs-benedict" :rating 10} + +; 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 + +(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 + +(edn/read-string {:readers {'MyYelpClone/MenuItem map->menu-item}} + "#MyYelpClone/MenuItem {:name \"eggs-benedict\" :rating 10}") +; -> #user.MenuItem{:name "eggs-benedict", :rating 10} + +``` + +# References + +- [EDN spec](https://github.com/edn-format/edn) +- [Implementations](https://github.com/edn-format/edn/wiki/Implementations) +- [Tagged Elements](http://www.compoundtheory.com/clojure-edn-walkthrough/) -- cgit v1.2.3 From 5789ae677260840f8239d0054b051b06ef32d98c Mon Sep 17 00:00:00 2001 From: Jason Yeo Date: Tue, 20 Oct 2015 22:35:07 +0800 Subject: Reword the intro, make section more obvious --- edn.html.markdown | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'edn.html.markdown') diff --git a/edn.html.markdown b/edn.html.markdown index b8dc4e88..14bb25b4 100644 --- a/edn.html.markdown +++ b/edn.html.markdown @@ -7,13 +7,12 @@ contributors: Extensible Data Notation or EDN for short is a format for serializing data. -The notation is used internally by Clojure to represent programs and -it is used commonly by Clojure and Clojurescript programs to transfer -data. Though there are implementations of EDN for many other -languages. +The notation is used internally by Clojure to represent programs and it also +used as a data transfer format like JSON. Though it is more commonly used in +Clojure land, there are implementations of EDN for many other languages. -The main benefit of EDN is that it is extensible, which we will see -how it is extended later on. +The main benefit of EDN over JSON and YAML is that it is extensible, which we +will see how it is extended later on. ```Clojure ; Comments start with a semicolon. @@ -37,8 +36,7 @@ false \g \r \a \c \e ; Keywords starts with a colon. They behave like enums. Kinda -; like symbols in ruby land. - +; like symbols in ruby. :eggs :cheese :olives @@ -74,7 +72,9 @@ false ; Sets are collections that contain unique elements. #{:a :b 88 "huat"} -;;; Tagged Elements +;;;;;;;;;;;;;;;;;;;;;;; +;;; Tagged Elements ;;; +;;;;;;;;;;;;;;;;;;;;;;; ; EDN can be extended by tagging elements with # symbols. -- cgit v1.2.3 From 4ff79b2554ca3d16e4b64d0d4b367191cdc31887 Mon Sep 17 00:00:00 2001 From: Jason Yeo Date: Wed, 28 Oct 2015 17:46:57 +0800 Subject: Fix minor typographical errors --- edn.html.markdown | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'edn.html.markdown') diff --git a/edn.html.markdown b/edn.html.markdown index 14bb25b4..b303d63c 100644 --- a/edn.html.markdown +++ b/edn.html.markdown @@ -22,7 +22,7 @@ will see how it is extended later on. ;;; Basic Types ;;; ;;;;;;;;;;;;;;;;;;; -nil ; or aka null +nil ; also known in other languages as null ; Booleans true @@ -35,14 +35,15 @@ false ; Characters are preceeded by backslashes \g \r \a \c \e -; Keywords starts with a colon. They behave like enums. Kinda -; like symbols in ruby. +; Keywords start with a colon. They behave like enums. Kinda +; like symbols in Ruby. :eggs :cheese :olives -; Symbols are used to represent identifiers. You can namespace symbols by -; using /. Whatever preceeds / is the namespace of the name. +; Symbols are used to represent identifiers. They start with #. +; You can namespace symbols by using /. Whatever preceeds / is +; the namespace of the name. #spoon #kitchen/spoon ; not the same as #spoon #kitchen/fork @@ -52,7 +53,7 @@ false 42 3.14159 -; Lists are a sequence of values +; Lists are sequences of values (:bun :beef-patty 9 "yum!") ; Vectors allow random access -- cgit v1.2.3 From 5f6d0d030001c465656661632fbea540a54bae69 Mon Sep 17 00:00:00 2001 From: Jason Yeo Date: Wed, 28 Oct 2015 17:51:18 +0800 Subject: Kinda -> Kind of --- edn.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'edn.html.markdown') diff --git a/edn.html.markdown b/edn.html.markdown index b303d63c..655c20f1 100644 --- a/edn.html.markdown +++ b/edn.html.markdown @@ -35,7 +35,7 @@ false ; Characters are preceeded by backslashes \g \r \a \c \e -; Keywords start with a colon. They behave like enums. Kinda +; Keywords start with a colon. They behave like enums. Kind of ; like symbols in Ruby. :eggs :cheese -- cgit v1.2.3 From a72017573d893b9c0b17e7342dbe39630ba4a5d0 Mon Sep 17 00:00:00 2001 From: bureken Date: Sat, 31 Oct 2015 03:33:13 +0300 Subject: Typo fix --- edn.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'edn.html.markdown') diff --git a/edn.html.markdown b/edn.html.markdown index 655c20f1..0a0dc9b5 100644 --- a/edn.html.markdown +++ b/edn.html.markdown @@ -16,7 +16,7 @@ will see how it is extended later on. ```Clojure ; Comments start with a semicolon. -; Anythng after the semicolon is ignored. +; Anything after the semicolon is ignored. ;;;;;;;;;;;;;;;;;;; ;;; Basic Types ;;; -- cgit v1.2.3 From 38506983bb1d589734268b62bb87b4bad4601733 Mon Sep 17 00:00:00 2001 From: Willie Zhu Date: Sat, 31 Oct 2015 15:27:44 -0400 Subject: [edn/en] Fix grammar --- edn.html.markdown | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'edn.html.markdown') diff --git a/edn.html.markdown b/edn.html.markdown index 0a0dc9b5..d0bdddfc 100644 --- a/edn.html.markdown +++ b/edn.html.markdown @@ -5,13 +5,13 @@ contributors: - ["Jason Yeo", "https://github.com/jsyeo"] --- -Extensible Data Notation or EDN for short is a format for serializing data. +Extensible Data Notation (EDN) is a format for serializing data. -The notation is used internally by Clojure to represent programs and it also +The notation is used internally by Clojure to represent programs. It is also used as a data transfer format like JSON. Though it is more commonly used in -Clojure land, there are implementations of EDN for many other languages. +Clojure, there are implementations of EDN for many other languages. -The main benefit of EDN over JSON and YAML is that it is extensible, which we +The main benefit of EDN over JSON and YAML is that it is extensible. We will see how it is extended later on. ```Clojure @@ -59,7 +59,7 @@ false ; Vectors allow random access [:gelato 1 2 -2] -; Maps are associative data structures that associates the key with its value +; Maps are associative data structures that associate the key with its value {:eggs 2 :lemon-juice 3.5 :butter 1} @@ -68,7 +68,7 @@ false {[1 2 3 4] "tell the people what she wore", [5 6 7 8] "the more you see the more you hate"} -; You may use commas for readability. They are treated as whitespaces. +; You may use commas for readability. They are treated as whitespace. ; Sets are collections that contain unique elements. #{:a :b 88 "huat"} @@ -82,11 +82,11 @@ false #MyYelpClone/MenuItem {:name "eggs-benedict" :rating 10} ; Let me explain this with a clojure example. Suppose I want to transform that -; piece of edn into a MenuItem record. +; 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 +; To transform EDN to clojure values, I will need to use the built in EDN ; reader, edn/read-string (edn/read-string "{:eggs 2 :butter 1 :flour 5}") -- cgit v1.2.3