diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-11-02 09:17:03 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-11-02 09:17:03 +0300 |
| commit | e216b9be95e2c52f62e27294714ba6bb8fd58d1f (patch) | |
| tree | cf590436b7f0cbfe70e4d15739004c2487bde2ab /core.fnl | |
| parent | 3b9aa01b8b82f8710eb19fc829b937af42d9dbcb (diff) | |
feature(core): more multimethod related functions
Diffstat (limited to 'core.fnl')
| -rw-r--r-- | core.fnl | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -423,4 +423,29 @@ found in the table." (set res not-found))) res)) +(fn* core.remove-method + [multifn dispatch-val] + (tset (. (getmetatable multifn) :multimethods) dispatch-val nil) + multifn) + +(fn* core.remove-all-methods + "Removes all of the methods of multimethod" + [multifn] + (let [mtable (. (getmetatable multifn) :multimethods)] + (each [k _ (pairs mtable)] + (tset mtable k nil)) + multifn)) + +(fn* core.methods + "Given a multimethod, returns a map of dispatch values -> dispatch fns" + [multifn] + (. (getmetatable multifn) :multimethods)) + +(fn* core.get-method + "Given a multimethod and a dispatch value, returns the dispatch `fn' +that would apply to that value, or `nil' if none apply and no default." + [multifn dispatch-val] + (or (. (getmetatable multifn) :multimethods dispatch-val) + (. (getmetatable multifn) :multimethods :default))) + core |