summaryrefslogtreecommitdiff
path: root/macros
diff options
context:
space:
mode:
authorAndrey Orst <andreyorst@gmail.com>2020-11-02 09:17:03 +0300
committerAndrey Orst <andreyorst@gmail.com>2020-11-02 09:17:03 +0300
commite216b9be95e2c52f62e27294714ba6bb8fd58d1f (patch)
treecf590436b7f0cbfe70e4d15739004c2487bde2ab /macros
parent3b9aa01b8b82f8710eb19fc829b937af42d9dbcb (diff)
feature(core): more multimethod related functions
Diffstat (limited to 'macros')
-rw-r--r--macros/core.fnl32
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]