camsaul / methodical

Functional and flexible multimethods for Clojure. Nondestructive multimethod construction, CLOS-style aux methods and method combinations, partial-default dispatch, easy next-method invocation, helpful debugging tools, and more.
Eclipse Public License 2.0
293 stars 19 forks source link

Store multifn in atom instead var #29

Open darkleaf opened 5 years ago

darkleaf commented 5 years ago

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

camsaul commented 3 years ago

Related: #52

camsaul commented 2 years ago

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.