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 /macros/core.fnl | |
| parent | 3b9aa01b8b82f8710eb19fc829b937af42d9dbcb (diff) | |
feature(core): more multimethod related functions
Diffstat (limited to 'macros/core.fnl')
| -rw-r--r-- | macros/core.fnl | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/macros/core.fnl b/macros/core.fnl index bbff020..de6a1b0 100644 --- a/macros/core.fnl +++ b/macros/core.fnl @@ -152,21 +152,23 @@ (let [docstring (if (string? (first opts)) (first opts)) opts (if docstring (rest opts) opts) dispatch-fn (first opts)] - `(local ,name - (let [multimethods# {}] - (setmetatable - {} - {:__call - (fn [_# ...] - ,docstring - (let [dispatch-value# (,dispatch-fn ...)] - ((or (. multimethods# dispatch-value#) - (. multimethods# :default) - (error (.. "No method in multimethod '" - ,(tostring name) - "' for dispatch value: " - dispatch-value#) 2)) ...))) - :multimethods multimethods#}))))) + (if (in-scope? name) + nil + `(local ,name + (let [multimethods# {}] + (setmetatable + {} + {:__call + (fn [_# ...] + ,docstring + (let [dispatch-value# (,dispatch-fn ...)] + ((or (. multimethods# dispatch-value#) + (. multimethods# :default) + (error (.. "No method in multimethod '" + ,(tostring name) + "' for dispatch value: " + dispatch-value#) 2)) ...))) + :multimethods multimethods#})))))) (fn* core.defmethod [multifn dispatch-val & fn-tail] |