From a discussion in hylang/hy#1346
(defmacro defshadowed [name args &rest body]
`(do
(defmacro ~name ~args ~@body)
(defn ~name ~args (~name ~@args))))
=> (defshadowed zerop [x]
... `(= ~x 0))
import hy
from hy import HyExpression, HyInteger, HySymbol
hy.macros.macro('zerop')((lambda x: HyExpression(((([] + [HySymbol('=')]) + [x]) + [HyInteger(0)]))))
def zerop(x):
return (x == 0)
None
=> (zerop 3) ; look ma, no function call!
(3 == 0)
False
=> (list (map zerop [0 1 2]))
list(map(zerop, [0, 1, 2]))
[True, False, False]
It's pretty limited, but sufficiently simple marcos could be shadowed this way in a single definition. This might be good enough for the type of things we'd want shadowed anyway.
From a discussion in hylang/hy#1346
It's pretty limited, but sufficiently simple marcos could be shadowed this way in a single definition. This might be good enough for the type of things we'd want shadowed anyway.