Skip to content

defshadowed #50

@gilch

Description

@gilch

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions