On Wed, Jan 4, 2012 at 07:36, Johnny Weng Luu <johnny.weng....@gmail.com> wrote: > One thing that seems weird is the way Clojure destructures a map > > I have this map: {:last-name "Vinge" :first-name "Vernor"} which is passed > to this function: (defn greet-author-2 [{fname :first-name}] ... ) > > Wouldn't it be better doing: (defn greet-author-2 [{:first-name fname}] ... > ) > > You first type the keyword, then followed by the parameter to bind to. It > reads that the value is bound to the parameter in the same place. > > Feels more natural to me in a way. > > Thoughts?
Doesn't make sense that way around. Remember that in a map, the key is unique, but the value need not be. Remember that in a Lisp this isn't just a question of arbitrary syntax. The code you write is always also a data structure. With the current solution I can write this, which while not obviously useful at least has an obvious meaning: (let [{name1 :name name2 :name} {:name "a"}] (= name1 name2)) Your proposal would seem to allow this: (let [{:first-name name :last-name name} {:last-name "last" :first-name "first"}] (= name ???)) It's not clear what this would mean. It would also make it impossible to bind the value for a given key to more than one variable, since map keys must be unique: (let [{:name name1 :name name2} {:name "a"}] ;; boom? ) // Ben -- 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