Data notation in Clojure - Ostash.Dev

submited by
Style Pass
2021-06-30 07:30:03

Homoiconisity (code as a data structure) is one of the pillars of the Clojure language. It gives the extensibility and flexibility to the language. For example we have a power to easily extend Clojure language by creating macros since in this process we can use all available functions for the data structures.

Furthermore, we can use Clojure syntax notation for the data serialization/de-serialization, data transfers between the server and a client (Clojure => ClojureScript). A set of rules (a standard) of organizing the data is called EDN - extensible data notation. A JSON format similarly was created with the syntax of the JavaScript language.

In order to serialize a data structure we would use a pr-str function. As the result we have a string that can be written in the file for example.

When you work with EDN files using functions spit (to write to a file) and slurp (to read from the file) it is very convenient. Since slurp returns a string, we have to use read-string again to de-serialize data to the Clojure map.

Leave a Comment