I might be wrong, but I think that would cause (add-item 1 {:prop
"here"}) to call the wrong defmethod (should call 4th, calls 2nd)

On Mon, Apr 16, 2012 at 12:47 PM, Ambrose Bonnaire-Sergeant
<abonnaireserge...@gmail.com> wrote:
> This should do the trick:
>
> (defmulti add-item (fn [i & other] (class i))
>
> Thanks,
> Ambrose
>
>
> On Mon, Apr 16, 2012 at 5:33 AM, James Thornton <james.thorn...@gmail.com>
> wrote:
>>
>> How do you use defmulti to create a function with a variable number of
>> args?
>>
>> For example, add-item is wrapping a Java method that can take a variable
>> number of args, and so here I am trying to make add-item take zero, one, or
>> two args. Notice there are two singe-arg funcs -- each taking a different
>> type...
>>
>> (defmulti add-item class)
>> (defmethod add-item [] (add-item nil nil))
>> (defmethod add-item Integer [id] (add-item id nil))
>> (defmethod add-item Map [props] (add-item nil props))
>> (defmethod add-item :default [id props] (  ; call some Java method )
>>
>> Unless I am overlooking something, I don't see anything on the
>> Multimethods page (http://clojure.org/multimethods) about defmulti or
>> defmethod taking a variable number of arguments -- they all take the same
>> number of arguments of different types.
>>
>> - James
>>
>> --
>> 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 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 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