So when you call them first and rest, how do you destructure lists of lists?
Actually, now that I think about it, "fire" is much cooler sounding than "cadr". But not as cool sounding as cadadr.
Actually, now that I think about it, "fire" is much cooler sounding than "cadr". But not as cool sounding as cadadr.
(def coll [[1 2 3]
[4 5 6]
[7 8 9]])
(second (second coll)) ; => 5
And often when I'm digging deep inside a nested data structure, I don't need just one piece of data, so destructuring comes in handy: (let [[[top-left]
[_ middle]
[_ _ bottom-right]] coll]
[top-left middle bottom-right]) ; => [1 5 9](I prefer pattern matching / destructuring-bind, though.)
In Clojure it's usually more idiomatic to use destructuring, which I think is much more understandable since the form follows the structure that is being accessed.
Or you can use get-in, which takes a sequence of keys to dig into a deep associative data structure. It doesn't work with sequences, but building highly nested seqs is rather uncommon in Clojure.
http://groups.google.com/group/clojure/browse_frm/thread/11a...