What may confuse is that map destructuring swaps the positions of keys and values as compared to map literals:
user> (let [{x :body} {:body 42}] x) 42 It does conform to the pattern that the bound variable precedes the value to bind in forms like let. A benefit of this ordering is that destructuring patterns like {:keys [a b c]} are unambiguous. Your posted example performs two levels of destructuring. It first extracts the value associated with the key :body in the map passed to the function as the first argument. It then extracts the head and the tail of this value (which is therefore assumed to be a sequence) and binds them to the local variables 'head' and 'body'. -Per On Fri, Apr 16, 2010 at 3:59 PM, Bytesource <stefan.rohlf...@gmail.com> wrote: > Hi, > > I am currently reading "Programming Clojure" but got stuck at the > destructuring done in the "head-overlaps-body?" function call that is > part of the "snake" game: > > (defn head-overlaps-body? [{[head & body] :body}] > (includes? body head)) > > ;; page 200 of the pdf version > > I can not figure out what {[head & body] :body} actually means here. > > "head-overlaps-body?" is called inside "lose?" which is called with a > "snake" object: > > (def lose? head-overlaps-body?) > > (defn create-snake [] > {:body (list [1 1]) > :dir [1 0] > :type :snake > :color (Color. 15 160 70)}) > > I read the the information about the "let" binding form on clojure.org/ > special_forms but still have no clue how the above destructuring is > done. > > Hope someone can give me a hint. > > Stefan > > -- > 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 -- 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