(defn my-dispatch [x] (...))
(defmulti my-multi #'my-dispatch)
Is this the most convenient/best way to be able to work with the defmulti dispatch function in a repl?
(without having to restart the repl..)
There's another trick, hum... I think it's just: (def my-multi nil) (defmulti my-multi ...)
Technically, I'm evaluating a clj file in vscode, so I'm not directly typing in the commands in the repl to redefine the dispatch. If it makes a difference..
What I'm typing in the repl is mostly the execution of various functions defined. Are you suggesting (def my-multi nil)
typed in the repl before saving my file, causing it to be reevaluated would get a new dispatch function defined? (nothing stopping me from trying it out...)
Ya, just put put the (def my-multi nil) above the defmulti definition
Then re-evaluate the file
Cool, I'll have to try it out. Thanks a bunch!
Now you can freely change your dispatch function, and it'll be reloaded by defmulti
It's because defmulti has a check that says don't reload if the var is already a multi-method. So it you make the var nil before reloading the check will be false and it'll reload defmulti
There's a difference between this trick and the one you posted before though. In this case you also need to reload the defmethods, cause reloading the defmulti will reset it too. Where as if you pass a var to the dispatch, that's not the case. So it depends what you want to do.
My use case at the moment is a fairly small file containing all related functions, so your method would work fine.
funny, I just came here to ask about the exact same problem 😄