Re: A question regarding map destructuring

2010-11-02 Thread Meikel Brandmeyer
Hi, On 2 Nov., 08:14, Mike Meyer wrote: > 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 t

Re: A question regarding map destructuring

2010-11-02 Thread Mike Meyer
On Mon, 1 Nov 2010 23:41:47 -0700 (PDT) Meikel Brandmeyer wrote: > Hi, > > On 2 Nov., 03:25, Mike K 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]) possi

Re: A question regarding map destructuring

2010-11-01 Thread Meikel Brandmeyer
Hi, On 2 Nov., 07:41, Meikel Brandmeyer wrote: > Hi, > > On 2 Nov., 03:25, Mike K wrote: > The map destructuring in the defn is a special case of defn, not > destructuring itself. > > (defn foo [& {:keys [a b]}] ...) > > is equivalent to > > (defn foo [& options#] (let [{:keys [a b]} (apply has

Re: A question regarding map destructuring

2010-11-01 Thread Meikel Brandmeyer
Hi, On 2 Nov., 03:25, Mike K 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? Vectors are indexed by integers. user=> (let [{a :a} [:b 7 :a 3]] [a]) [nil]

Re: A question regarding map destructuring

2010-11-01 Thread Mike Meyer
On Mon, 1 Nov 2010 19:25:59 -0700 (PDT) Mike K wrote: > This question is a bit abstruse, so please bear with me :-) [elided] > So this can't be how it works, but I don't know how else to interpret > the documentation. Is this a special case meaning "if there are > optional arguments AND they are

A question regarding map destructuring

2010-11-01 Thread Mike K
This question is a bit abstruse, so please bear with me :-) Here is an example of a function with named arguments and default values from the book "The Joy of Clojure". It uses optional arguments (via &) and map destructuring. (defn slope [& {:keys [p1 p2] :or {p1 [0 0] p2 [1 1]}}] (float (