4 ms·
Rich Hickey on Clojure 1.4's Extensible Reader, ClojureScript
- nickik 15y agoThe Extensible Reader is really the next step in terms of a common extensible data exchange format. Atm everybody builds this himself for his application, this commes with alot of wheel reinvention. Make it extensible is the first step to find out whats most used. People can find each other and creat common abstractions.
- fogus 15y agoA simple example reading a UUID of the form `#uuid "550e8400-e29b-41d4-a716-446655440000"` is found at https://github.com/clojure/clojure/blob/master/src/clj/clojure/uuid.clj https://github.com/clojure/clojure/blob/master/src/clj/cloju... A much more complex example reading a UTC instant in time like `#inst "2010-11-12T13:14:15.666-06:00"` is found at https://github.com/clojure/clojure/blob/master/src/clj/clojure/instant.clj https://github.com/clojure/clojure/blob/master/src/clj/cloju...
- gosub 15y agoI can't see the gain of: #uuid "550e8400-e29b-41d4-a716-446655440000" over: (uuid "550e8400-e29b-41d4-a716-446655440000") The reader already supports it, functions/macro are already namespaced and you still have to parse it anyway.
- zaph0d 15y agoSomething like `(uuid "550e8400-e29b-41d4-a716-446655440000")` can't be carried around as data whereas `#uuid "550e8400-e29b-41d4-a716-446655440000"` can be. Think about data interchange between Clojure & ClojureScript.
- gosub 15y agoI do not understand what do you mean by "carried around as data", a s-expr is data. Could you give me an example where you can't use the first form?
- spacemanaki 15y agoI think the issue is that in order to use the first form, you would need to eval the s-expr after reading it, which is potentially dangerous and fragile. But also, ClojureScript doesn't have run-time eval. Of course, you could interpret the s-expr as some kind of tagged list (or more likely use a vector like [:uuid "550..."]) and instead of eval-ing check the first element etc, but at that point, why not have an extensible reader do that for you?
- cemerick 15y agoOf course `(uuid "…")` can be carried around as data; it's a list containing a symbol and a string, just like `#uuid "…"` is a tag and a string. The difference is that the latter is evaluated at read-time with constrained semantics, rather than requiring the full force and latitude of `eval`. i.e. definitely helpful for data interchange between Clojure implementations (and read-time shenanigans in general), and a big improvement over the depths of #= and such.
- zaph0d 15y ago+1.
- deleted 15y ago[deleted]
- nickik 15y agoWell sure you can just pass around clojure code and eval it but the point is to have it in the reader. Other languages can interface to that read. (uuid ....) does not work when you dont have a clojure evaluater on the reciver.