On Mon, 1 Nov 2010 23:41:47 -0700 (PDT) Meikel Brandmeyer <m...@kotka.de> wrote:
> Hi, > > On 2 Nov., 03:25, Mike K <mbk.li...@gmail.com> wrote: > > > (print-value-a [:b 7 :a 3]) > > ; actually prints nil > > You have to use apply. (apply print-value-a [:b 7 :a 3]). > > Furthermore: how could (let [{a :a} [:b 7 :a 3]] [a]) possibly work? The same way this one works: > (defn foo [& {:keys [a b]}] ...) > > is equivalent to > > (defn foo [& options#] (let [{:keys [a b]} (apply hash-map > options#)] ...)) This only happens if the rest argument destructuring is a hash map - if I use a vector or a symbol there, then the values don't get turned into a map. Can't that same mechanism be used in the case where some non-rest argument is a hash-map trying to destructure a sequence? So that: (let [{a :a} [:b 7 :a 3]] ...) would be equivalent to (let [x# [:b 7 :a 3]] (let [{a :a} (apply hash-map x#)] ...) > user=> (let [{a :a} [:b 7 :a 3]] [a]) > [nil] > user=> (let [{a 2} [:b 7 :a 3]] [a]) > [:a] > > The map destructuring in the defn is a special case of defn, not > destructuring itself. Interesting. This means you can't use your second example to destructure a rest argument: user=> ((fn [& {a 2}] [a]) :b 7 :a 3) [nil] But that's the same behavior as you got with 1.1. But this case: user=> ((fn [& {a 2}] [a]) 1 7 2 3) [3] ;; 1.2 behavior; 1.1 returns [nil] Changed between 1.1 and 1.2. As much as I hate special cases when they aren't needed, I'm not arguing that this should change. Handling rest arguments that way is very useful. It's not at all clear there's a use for doing this anywhere case, other than to scratch that consistency itch. <mike -- Mike Meyer <m...@mired.org> http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- 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