On Wed, Jun 16, 2010 at 7: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.
>

I would do it like this, a la Python:

(defn foo [a b & {:keys [c d]}]
  (println a b c d))

(defn ** [m]
  (apply concat (vec m)))

(apply foo 1 2 (** {:c 3 :d 4}))

(apply apply [foo 1 2 (** {:c 3 :d 4})])

The problem with your apply* is that it's macro so it can't be used as an
fn.

David

-- 
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

Reply via email to