diff options
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] |