More reasonable.. On Oct 27, 7:15 am, Stuart Halloway <stuart.hallo...@gmail.com> wrote: > > checking out the "Try Clojure": > > > if you type the following, you get output that matches what you typed > > in every case except for lists. > > > Vectors: --> [1 2 3 4] > > [1 2 3 4] > > > Maps: --> {:foo "bar" 3 4} > > {:foo "bar" 3 4} > > > Lists: --> '(1 2 3 4) > > (1 2 3 4) <----- *INCONSISTENT* why not render this as '(1 2 3 4) ... > > this would make much more sense to newbies. > > > Sets: --> #{1 2 3 4} > > #{1 2 3 4} > > This is an interesting question. Consistency is important, but consistency > with what? Your mental model for what happens at the REPL needs to keep the > R, E, and P steps clearly separate. > > Working backward: the P (Print) prints things in a way that they can be read > back, where possible: > > (read-string "[1 2 3 4]") > => [1 2 3 4] > > (read-string "(1 2 3 4)") > => (1 2 3 4) > > (read-string "#{1 2 3 4}") > => #{1 2 3 4} > > (read-string "{1 2 3 4}") > => {1 2, 3 4} > > If the P part of the REPL put a tick in front of lists, they would not read > back correctly: > > (read-string "'(1 2 3 4)") > => (quote (1 2 3 4)) <---- INCONSISTENT > > Now to the R (Reader) part. If, as you suggest, the tick were part of the > reader syntax for lists, you could "fix" the inconsistency above: > > ;; hypothetical Clojure with '(...) list literals > (read-string "' '(1 2 3 4)") > => (1 2 3 4) > > Finally, consider the poor E (Evaluator) in this scenario. The evaluator > must (1) evaluate lists except (2) *not* evaluate lists that are protected by > quote. But now that the tick is part of the syntax you have two challenges: > > (1) Since the tick no longer prevents evaluation, you have to spell out the > quote (and still use the tick!) > > ;; hypothetical literal list > (quote '(1 2 3)) > > (2) Since the tick is required as part of list syntax, your programs have to > be written with ticks everywhere like this: > > '(defn hello-world > [] > '(println "hello") > > You have to understand R, E and P as separate steps to understand the REPL. > > As a side note, it is worth mentioning that the REPL is composed of three > simple parts, and that interactive shells that do not have this factoring are > much less useful. Imagine if your language didn't separate reading and > evaluating. You would need JSON or something to serialize data... > > Stu > > Stuart Halloway > Clojure/corehttp://clojure.com
-- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en