methodical icon indicating copy to clipboard operation
methodical copied to clipboard

Store multifn in atom instead var

Open darkleaf opened this issue 6 years ago • 2 comments

ClojureScript has a stripped-down implementation of vars and does not have the alter-var-root! function.

How to store multifn in atom like clojurescript does? https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/core.cljc#L2768

Or maybe just use mutable field?

For clojurescript support #20

darkleaf avatar Sep 12 '19 11:09 darkleaf

Related: #52

camsaul avatar Jun 04 '21 05:06 camsaul

It looks like ClojureScript stores the individual bits of a multimethod in atoms rather than the entire multimethod itself

https://github.com/clojure/clojurescript/blob/e8643ab1cbaae9b01d3ed306711883f6473115aa/src/main/clojure/cljs/core.cljc#L2791-L2798

I need to think about how we could do something like this without affecting programmatic/functional multimethod manipulation -- if you do something like this:

(m/defmulti mf ...)

(let [mf2 (m/add-primary-method mf ...)]
  ...)

mf2 should not affect mf at all -- sort of like how assoc doesn't mutate the original map. If we used atom(s) everywhere it would bust things (unless add-primary-method copied the existing atom(s) into new atom(s)... maybe that would work).

I think either way we can get away with storing the entire impl in a single atom rather than having several atoms.

camsaul avatar Sep 09 '22 16:09 camsaul