There is no easy way to change the dispatch function interactively. Our 
experience has been that doing this (without the magic to hunt down all the 
defmethods elsewhere) was causing more harm than good.

It's a tradeoff, for sure.

Stu

> I just noticed this in the 1.2 beta release notes:
> 
>  * defmulti - Enhanced to have defonce semantics
> 
> I've been bitten by this for a couple months now and I never knew the
> reason.  If (during interactive development) you want to change the
> dispatch function for a multimethod, what is now the proper way?
> 
> I used to be able to just rerun the defmulti or recompile/reload the
> file containing the defmulti.  I'd lose all the methods defined for
> that multimethod (which sometimes forced me to hunt down all the files
> that defined methods on it and recompile them all too), but I could
> live with that.
> 
> Clojure 1.1.0
> user=> (defmulti foo (fn [x] x))
> #'user/foo
> user=> (defmulti foo (fn [x y] x))
> #'user/foo
> user=> (defmethod foo :foo [x y] y)
> #<MultiFn clojure.lang.mult...@5eb7ec5d>
> user=> (foo :foo :bar)
> :bar
> 
> But now:
> 
> Clojure 1.2.0-beta1
> user=> (defmulti foo (fn [x] x))
> #'user/foo
> user=> (defmulti foo (fn [x y] x))   ;;does nothing
> nil
> user=> (defmethod foo :foo [x y] y)
> #<MultiFn clojure.lang.mult...@4b14b82b>
> user=> (foo :foo :bar)
> java.lang.IllegalArgumentException: Wrong number of args (2) passed
> to: user$eval1$fn (NO_SOURCE_FILE:0)
> 
> I've been putting
> 
> (def foo nil)
> (defmulti foo ...)
> 
> in a bunch of my source files to force recompilation whenever the
> files are recompiled.
> 
> 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

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