... the other half of the answer being that when you have rest args with (defn foo [& args] ...), "args" is bound to a seq.
On Wed, Aug 27, 2014 at 11:27 AM, Ben Wolfson <wolf...@gmail.com> wrote: > The reason is that in the macroexpansion of "let", map-based destructuring > has a seq? test which the list passes but the vector doesn't: > > > (clojure.pprint/pprint (macroexpand-1 '(let [{:keys [a b]} [:a 1]] a))) > (let* > [map__34214 > [:a 1] > map__34214 > (if > (clojure.core/seq? map__34214) > (clojure.lang.PersistentHashMap/create > (clojure.core/seq map__34214)) > map__34214) > b > (clojure.core/get map__34214 :b) > a > (clojure.core/get map__34214 :a)] > a) > > Presumably this is because vectors can also be accessed with "get", so you > can do something like this: > > > (let [{a 0} [:a 1]] a) > :a > > ... confusing though it is. > > > > On Wed, Aug 27, 2014 at 11:20 AM, John Gabriele <jmg3...@gmail.com> wrote: > >> Why is it that although this works: >> >> ~~~clojure >> (defn foo [& args] (let [{:keys [a b]} args] (str a \~ b))) >> ;;=> #'some-app.core/foo >> (foo :a 1 :b 2) >> ;;=> "1~2" >> ~~~ >> >> this does not: >> >> ~~~clojure >> (let [{:keys [a b]} [:a 1 :b 2 :c 3]] (str a \~ b)) >> ;;=> "~" >> ~~~ >> >> ? >> >> And even stranger, *this* *does* work: >> >> ~~~clojure >> ;; Changed vector to a list. >> (let [{:keys [a b]} '(:a 1 :b 2 :c 3)] (str a \~ b)) >> ;;=> "1~2" >> ~~~ >> >> ? >> >> Incidentally, I see that the following `let` also does indeed work: >> >> ~~~clojure >> (let [ [& {:keys [a b]}] [:a 1 :b 2 :c 3] ] (str a \~ b)) >> ;;=> "1~2" >> ~~~ >> >> Thanks! >> >> -- >> 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 unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Ben Wolfson > "Human kind has used its intelligence to vary the flavour of drinks, which > may be sweet, aromatic, fermented or spirit-based. ... Family and social > life also offer numerous other occasions to consume drinks for pleasure." > [Larousse, "Drink" entry] > > -- Ben Wolfson "Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure." [Larousse, "Drink" entry] -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.