Skip to content

Commit

Permalink
Update let for the removal of special forms
Browse files Browse the repository at this point in the history
Co-authored-by: Allison Casey <allie.jo.casey@gmail.com>
  • Loading branch information
Kodiologist and allison-casey committed Jul 2, 2021
1 parent 3315b94 commit 6dd1768
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions hy/contrib/walk.hy
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[collections [OrderedDict]]
[hy.macros [macroexpand :as mexpand]]
[hy.compiler [HyASTCompiler calling-module]]
[hy.extra.reserved [special]])
hy.extra.reserved)

(defn walk [inner outer form]
"``walk`` traverses ``form``, an arbitrary data structure. Applies
Expand Down Expand Up @@ -220,13 +220,15 @@
[(= (get form 0) (hy.models.Symbol "require"))
(ast-compiler.compile form)
(return)]
[True (traverse (mexpand form ast-compiler.module ast-compiler))])
[(in (get form 0) '[except unpack-mapping])
(hy.models.Expression [(get form 0) #* (traverse (cut form 1 None))])]
[True (traverse (mexpand form ast-compiler.module ast-compiler :result-ok False))])
(if (coll? form)
(traverse form)
form)))
(expand form))

(setv _mangled-special (frozenset (map hy.mangle (special))))
(setv _mangled-core-macs (frozenset (map hy.mangle (hy.extra.reserved.macros))))


(defn lambda-list [form]
Expand Down Expand Up @@ -466,7 +468,7 @@
[(= head 'match) (self.handle-match)]
[(= head 'quasiquote) (self.+quote)]
;; must be checked last!
[(in (hy.mangle head) _mangled-special) (self.handle-special-form)]
[(in (hy.mangle head) _mangled-core-macs) (self.handle-special-form)]
;; Not a special form. Traverse it like a coll
[True (self.handle-coll)]))

Expand Down
4 changes: 2 additions & 2 deletions hy/core/language.hy
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
"
(+ n 1))

(defn macroexpand [form]
(defn macroexpand [form [result-ok False]]
"Return the full macro expansion of `form`.
.. versionadded:: 0.10.0
Expand All @@ -327,7 +327,7 @@
"
(import hy.macros)
(setv module (calling-module))
(hy.macros.macroexpand form module (HyASTCompiler module)))
(hy.macros.macroexpand form module (HyASTCompiler module) :result-ok result-ok))

(defn macroexpand-1 [form]
"Return the single step macro expansion of `form`.
Expand Down
4 changes: 2 additions & 2 deletions hy/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
return False


def macroexpand(tree, module, compiler=None, once=False):
def macroexpand(tree, module, compiler=None, once=False, result_ok=True):
"""Expand the toplevel macros for the given Hy AST tree.
Load the macros from the given `module`, then expand the (top-level) macros
Expand Down Expand Up @@ -338,7 +338,7 @@ def macroexpand(tree, module, compiler=None, once=False):
from hy.compiler import Result
from ast import AST
if isinstance(obj, (Result, AST)):
return obj
return obj if result_ok else tree

if isinstance(obj, Expression):
obj.module = inspect.getmodule(m)
Expand Down

0 comments on commit 6dd1768

Please sign in to comment.