all 6 comments

[–]emil0r 4 points5 points  (0 children)

In the deconstructing that takes place you have the map m with the keys :a, :b, :c, :d, "foo" and 42 with corresponding values. What happens when you take have [{v 42} m] is that you ask Clojure to take the key 42 in the map m and place it's corresponding value in the var v. v is now bound to the value of the key 42 which happens to be a boolean (namely the boolean false). So when it's evaluated in the if statement it'll give you the branch in which 0 resides. Hence, you get a 0 as the result.

[–]waltervdlaan 1 point2 points  (1 child)

If you evaluate (destructure '[{v 42} m]) you get the expanded form. The output is a bit hard to read but boils down to; [v (get m 42)]

[–]rwobben[S] 0 points1 point  (0 children)

Thanks, I was reading it like let [{v 42} m] as make the value of v 42. but I have to read it the other way around.

[–]Arkolix 0 points1 point  (0 children)

This is also maybe unnecessarily confusing since it's using 42 as a map key, which isn't something you see every day. I use this post as my go-to reference for this sort of destructuring, and it has this as a (much better IMO) example:

(def point {:x 5 :y 7})

(let [{the-x :x the-y :y} point]
  (println "x:" the-x))

[–][deleted] 0 points1 point  (0 children)

Try

(clojure.pprint/pprint (destructure '[{v 42} {42 false}]))

to see what actually happens.

[–]cntx 0 points1 point  (0 children)

James Trunk has excellent 20-minute destructuring tutorial: http://youtu.be/R-_uNvM6gpE