Comments (5)
@acobster I'm not sure we'd be able to support aux methods on vanilla multimethods. I was thinking more that we'd let you use clojure.core/defmethod
and the like on a Methodical multimethod -- this would let you change your own defmulti
s to Methodical ones without breaking usage of it.
I think this should be possible, because clojure.lang.MultiFn
isn't final
: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/MultiFn.java#L18
from methodical.
If I'm understanding correctly, the goal of this is to allow users to use advanced methodical techniques even on multimethods defined upstream in library code out of their control? So for example:
(ns my.project
(require
[methodical.core :as m]
[some.upstream.lib :as lib]))
(m/defmethod lib/vanilla-multimethod :before :default [x]
(do-stuff x))
Because that would be truly awesome.
Maybe I'm just missing something, but is it possible to accomplish this by delegating to clojure.lang.MultiFn
rather than inheriting from it? So in the above example, m/defmethod
would detect in some way that lib/vanilla-multimethod
is an instance of clojure.lang.MultiFn
and call (.addMethod lib/vanilla-multimethod ...)
instead of your standard implementation. I believe you could even do this with a protocol that encapsulates only your util
fns that map directly on to MultiFn
's public methods, such as add-primary-method!
:
(defprotocol MethodicalMultiFn
(add-primary-method! [multifn-var dispatch-val f])
...)
(extend-protocol MethodicalMultiFn
clojure.lang.MultiFn
(add-primary-method! [multifn-var dispatch-val f]
(.addMethod (deref multifn-var) dispatch-val f))
...
StandardMultiFn
(add-primary-method! [multifn-var dispatch-val f]
...standard impl...))
I only just started looking at this and don't really understand how auxiliary methods are implemented yet, but in theory as long as your Var -> MethodTable
mapping code doesn't care whether the var is a vanilla vs. methodical instance, I think your auxiliary method implementations won't need to change.
from methodical.
For ClojureScript, there's an IMultiFn
protocol we could implement https://github.com/clojure/clojurescript/blob/4a73bc8b4c95cfedc614dcabb0fe1795da371d37/src/main/cljs/cljs/core.cljs#L11170-L11179
For JVM Clojure there's no protocol, so we'd have to subclass clojure.lang.MultiFn
. I think we'd have to use gen-class
, but then it wouldn't work with ClojureScript. So I think we'll need to have separate implementations of StandardMultiFn
for Clojure and ClojureScript. Maybe proxy
will work, but IIRC that does runtime lookup of methods which would hurt performance
from methodical.
Don't think gen-class
is going to work since we have to AOT it, and that requires all of the protocols it implements to be AOT'ed too... generating our own bytecode with something like insn
(wraps ASM
) might be our best bet.
from methodical.
proxy-plus
might actually be perfect for this
from methodical.
Related Issues (20)
- The `next-method` should have effective dispatch value metadata
- `trace!` and `untrace!` facilities to trace existing existing code without changing it HOT 1
- Should we error (or at least log a warning?) if aux methods have ambiguous order?
- `effective-dispatch-value` calculated incorrectly with aux methods when preferences are involved
- Add a `defmethod` hook to multimethods to do custom stuff when a new method is added HOT 2
- Kondo linter config for `defmethod` should do something that makes `next-method` an error when called with the wrong number of args
- Add `fdef` specs for all the macros HOT 1
- Effective dispatch value is incorrectly cached for `nil` HOT 1
- `defmulti` should support spec to use to validate dispatch values for `defmethod` forms
- Update documentation for 0.14.0 changes
- Should methods get an implicit `&dispatch-value` arg?
- Ambiguous primary method errors should tell you WHAT method has the ambiguity
- Add some sort of ambiguous method hook HOT 1
- Move the `Describable` protocol into `methodical.interface` so it can be with its friends (all the other protocols)
- Var metadata for multimethods created by `defmulti` doesn't get updated when metadata on symbol changes
- Figure out how to make Kondo complain when you don't use the result of something like `prefer-method`
- `methodical.impl.method-table.standard/dispatch-value-map` breaks for method tables with both keywords and compound dispatch values
- Fix custom Kondo hooks that result in `:redundant-fn-wrapper` errors
- `:dispatch-value-spec` should get wrapped in `nonconforming`
- Any plan to make `defmethod` to support schema like malli?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from methodical.