Arity problem with multi-methods

1,183 views
Skip to first unread message

Christian Sperandio

unread,
Nov 21, 2012, 5:14:10 PM11/21/12
to clo...@googlegroups.com
Hi,

I try to define multi-methods but when I call one I get an exception.

I declared the multi-methods like below:

(defmulti new-food-item (fn [food expiration]
                          (if (number? expiration)
                            ::duration
                            ::expiration-date)))

(defmethod new-food-item ::duration [food expiration-duration]
  (let [expiration-date (GregorianCalendar.)]
    (.add expiration-date GregorianCalendar/DAY_OF_MONTH expiration-duration)
    {:name food :expiration-date expiration-date}))

(defmethod new-food-item ::expiration-date [food expiration-date]
  {:name food :expiration-date expiration-date})


And when I do: (new-food-item "tomatoes" 5)
I get this exception:
ArityException Wrong number of args (2) passed to: core$class  clojure.lang.AFn.throwArity (AFn.java:437)

I don't understand where is the problem :/

Some help?

Thank you.

Chris

grinnbearit

unread,
Nov 21, 2012, 8:33:50 PM11/21/12
to clo...@googlegroups.com
Hi Chris,

If you change multimethod arities you'll have to def the multimethod to nil or restart the swank/nrepl server. It doesn't update that on recompilation.

Sidhant

Christian Sperandio

unread,
Nov 22, 2012, 2:45:48 AM11/22/12
to clo...@googlegroups.com
Thank you !
I became crazy because I didn't see the problem in my code. 

Why is there this issue with multi-methods? (and not with standard functions)


Chris
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Baishampayan Ghose

unread,
Nov 22, 2012, 2:51:03 AM11/22/12
to Clojure Group
Christian,

defmulti has defonce-like semantics which I guess is to prevent the associated defmethods from being wiped out when the form is recompiled.


-BG
--
Baishampayan Ghose
b.ghose at gmail.com

Art Goldhammer

unread,
Jul 19, 2019, 11:49:33 AM7/19/19
to Clojure
Seven years later, a big thank you from me. I was also being driven crazy by this bug. It is insane that this not better documented. In any case it should have been fixed by now.


On Thursday, November 22, 2012 at 2:51:03 AM UTC-5, Baishampayan Ghose wrote:
Christian,

defmulti has defonce-like semantics which I guess is to prevent the associated defmethods from being wiped out when the form is recompiled.


-BG
On Wed, Nov 21, 2012 at 11:45 PM, Christian Sperandio <christian...@gmail.com> wrote:
Thank you !
I became crazy because I didn't see the problem in my code. 

Why is there this issue with multi-methods? (and not with standard functions)


Chris

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 clo...@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

For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Zyxmn Daley Jes

unread,
May 19, 2021, 8:52:50 AM5/19/21
to Clojure
Thank you all!
Reply all
Reply to author
Forward
0 new messages