came across over the net the following examples.
I can understand full destructuring because "[" and "]"
mirrors the structure of tree.
But in partial desctructuring, [[a [b]] has extra pair of outer-most
[] which leads to confusion. Any explanation on that?
Also not sure about the last (on strings).
Thanks in advance
sun
(def flat "flat")
(def tree '(("one" ("two")) "three" ((("four")))))
;; Simple binding (like Common Lisp's LET*).
(let [var1 flat
var2 tree]
(list var1 var2))
-> ("flat" (("one" ("two")) "three" ((("four")))))
;; Full destructuring.
(let [var1 flat
[[a [b]] c [[[d]]]] tree]
(list var1 a b c d))
-> ("flat" "one" "two" "three" "four")
;; Partial destructuring.
(let [[[a [b]] & leftover :as all] tree]
(list a b leftover all))
-> ("one" "two" ("three" ((("four"))))
(("one" ("two")) "three" ((("four")))))
;; Works on strings, too.
(let [[a b c & leftover] "123go"]
(list a b c leftover))
-> (\1 \2 \3 (\g \o))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---