multimethods, uberjar, and several namespaces

103 views
Skip to first unread message

Erik Assum

unread,
Nov 23, 2016, 2:31:21 PM11/23/16
to clo...@googlegroups.com
Hi,

I’ve got a defmulti defined in a namespace and it’s corresponding defmethods defined in other namespaces.
This works fine when working in the repl, but when creating an uberjar, the defmethods in the other namespaces
don’t seem to be found.

I’ve created a minimal case here:

https://github.com/slipset/multitest

There is probably something simple I’m missing, but I cannot seem to find it.

What am I missing?

Erik.

Jonathan Fischer

unread,
Nov 23, 2016, 2:50:59 PM11/23/16
to Clojure
In your minimal case: nothing ever imports multitest.other, so the defmethod never gets loaded.

Erik Assum

unread,
Nov 23, 2016, 2:53:55 PM11/23/16
to clo...@googlegroups.com
So, I guess my question then would be, how do I make it load without creating a circular dependency?

Erik. 
-- 
i farta
--
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
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jonathan Fischer

unread,
Nov 23, 2016, 4:16:31 PM11/23/16
to Clojure
Just move your defmulti form out of the namespace that's using it, core in this case.  Like this:

Erik Assum

unread,
Nov 23, 2016, 4:32:06 PM11/23/16
to clo...@googlegroups.com
That would work. 

But I would like to argue that the need to require all possible namespaces which may implement a defmethod is a bit, should I say, closed?

This would mean that you can't build a plugin system based on multi methods, right?

Erik. 
-- 
i farta

Jonathan Fischer

unread,
Nov 23, 2016, 4:40:58 PM11/23/16
to Clojure
Just the opposite: it means that, at runtime, you can simply load in a file with your new defmethods and the multimethod gets updated to call through to them dynamically. That's what you see when you're working at the REPL: reloading a file (or typing in a new defmethod directly) is updating your multimethod to call the newer implementation.
Reply all
Reply to author
Forward
0 new messages