This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-12
Channels
- # adventofcode (78)
- # announcements (5)
- # babashka (22)
- # beginners (230)
- # calva (18)
- # cider (26)
- # clj-kondo (1)
- # cljs-dev (1)
- # clojure (14)
- # clojure-austin (1)
- # clojure-dev (3)
- # clojure-europe (30)
- # clojure-switzerland (1)
- # clojure-uk (26)
- # clojurescript (33)
- # conjure (2)
- # cursive (2)
- # data-science (1)
- # datomic (9)
- # docker (1)
- # emacs (8)
- # events (4)
- # fulcro (64)
- # lambdaisland (3)
- # luminus (1)
- # off-topic (3)
- # pathom (6)
- # portal (1)
- # programming-beginners (5)
- # shadow-cljs (22)
- # tools-deps (8)
- # xtdb (4)
(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?
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...)
Cool, I'll have to try it out. Thanks a bunch!
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.
(without having to restart the repl..)