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 Carper <briancar...@gmail.com> 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 [:quux]}) > (foo 1 ?????) > > I feel like I may be missing some simple way of doing it. I find > myself needing to do this pretty often, for example any time I have a > chain of functions calling each other that all take keyword arguments > on the end. > > (apply foo 1 (apply concat (seq args))) works, but that's awfully > nasty. So this is what I've been doing: > > (defmacro apply* [& args] > `(apply ~@(butlast args) (apply concat (seq ~(last args))))) > > (apply* foo 1 args) > => [1 {:bar 2, :baz [:quux]}] > > Kind of hacky though. Is there a better/shorter/builtin way? > > I can go back to using [x & args] in the function signature and (apply > hash-map args) in the function body, but I love having the keyword > destructuring in the function signature, since the user can see which > keys are valid to pass in, whenever I use {:keys [...]}. > > Thanks > --Brian -- 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