Hash-map destructuring

2010-06-16 Thread Brian Carper
Given: (defn foo [x & {:as args}] [x args]) (foo 1 :bar 2 :baz [:quux]) => [1 {:bar 2, :baz [:quux]}] If I have those rest-arguments already in a map, what's the most elegant way to call foo with them? (def args {:bar 2 :baz [:quux]}) (foo 1 ?) I feel like I may be missing some simple way o

Re: Hash-map destructuring

2010-06-16 Thread ataggart
There's a disconnect between the function definition and the datastructures used by the caller. Either fix the data structure: (def args [:bar 2 :baz [:quux]]) then use apply Or change the function definition to take a map: (defn foo [x {:keys [bar baz]}] ...) On Jun 16, 4:00 pm, Brian Carpe

Re: Hash-map destructuring

2010-06-16 Thread Michael Gardner
On Jun 16, 2010, at 7:07 PM, ataggart wrote: > There's a disconnect between the function definition and the > datastructures used by the caller. > > Either fix the data structure: > (def args [:bar 2 :baz [:quux]]) > then use apply > > Or change the function definition to take a map: > (defn foo

Re: Hash-map destructuring

2010-06-25 Thread Chas Emerick
On Jun 16, 2010, at 9:21 PM, Michael Gardner wrote: On Jun 16, 2010, at 7:07 PM, ataggart wrote: There's a disconnect between the function definition and the datastructures used by the caller. Either fix the data structure: (def args [:bar 2 :baz [:quux]]) then use apply Or change the funct

Re: Hash-map destructuring

2010-06-25 Thread Brian Carper
On Jun 25, 2:57 am, Chas Emerick wrote: > This is fairly simple: > > user=> (defn foo [& {:as args}] [args]) > #'user/foo > user=> (def m {:a 5 :b 6}) > #'user/m > user=> (apply foo (-> m seq flatten)) > [{:a 5, :b 6}] > > I'm not sure if it could be made easier, short of changing apply   > (which

Re: Hash-map destructuring

2010-06-25 Thread David Nolen
On Wed, Jun 16, 2010 at 7:00 PM, Brian Carper wrote: > Given: > > (defn foo [x & {:as args}] [x args]) > (foo 1 :bar 2 :baz [:quux]) > => [1 {:bar 2, :baz [:quux]}] > > If I have those rest-arguments already in a map, what's the most > elegant way to call foo with them? > > (def args {:bar 2 :baz