B Smith-Mannschott <[email protected]> writes:

> expected: nil
>   actual: java.lang.IllegalArgumentException: No method in multimethod
> 'sqrt' for dispatch value: :clojure.contrib.complex-numbers/complex

Just thought I'd expand on what the problem was.

I was able to reproduce this on an older Linux machine and narrowed it
down to being triggered by clojure.contrib.test-load-all reloading all
the namespaces.  Then Rich spotted the actual cause: test-load-all uses
a hash set to store the namespaces.  The ordering imposed by the set's
hash function can, it seems, vary in different environments, so on some
machines the complex-numbers namespace would be reloaded before
generic.math-functions, which meant the sqrt multimethod would lose the
method for complex numbers, hence the above exception.

As Mark mentioned Rich has committed a change to defmulti so that
multimethods can only be defined once.  (This just affects defmulti, not
defmethod).

http://github.com/richhickey/clojure/commit/1b8d5

This makes reloading namespaces safer, but there's a subtle change for
interactive development.  To clear a multimethod you now need to
explicitly call the (newly added) remove-all-methods function.  To
actually redefine it and change the dispatch function you have to unmap
it or def it to something else, before calling defmulti again, eg:

  (defmulti foo :a)
  (ns-unmap *ns* 'foo)
  (defmulti foo :b)

or

  (defmulti foo :a)
  (def foo nil)
  (defmulti foo :b)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to