Add the (require) form.
This commit is contained in:
parent
11adfa6564
commit
2426237916
@ -1197,6 +1197,19 @@ class HyASTCompiler(object):
|
||||
col_offset=operator.start_column)
|
||||
return operand
|
||||
|
||||
@builds("require")
|
||||
def compile_require(self, expression):
|
||||
"""
|
||||
TODO: keep track of what we've imported in this run and then
|
||||
"unimport" it after we've completed `thing' so that we don't polute
|
||||
other envs.
|
||||
"""
|
||||
expression.pop(0)
|
||||
for entry in expression:
|
||||
__import__(entry) # Import it fo' them macros.
|
||||
return ast.Pass(lineno=expression.start_line,
|
||||
col_offset=expression.start_column)
|
||||
|
||||
@builds("and")
|
||||
@builds("or")
|
||||
@checkargs(min=2)
|
||||
|
@ -686,3 +686,11 @@
|
||||
(assert (= foo 2))
|
||||
(setf foo (try (+ 2 2) (except [NameError] (+ 1 1))))
|
||||
(assert (= foo 4)))
|
||||
|
||||
|
||||
(defn test-require []
|
||||
(try
|
||||
(assert (= "this won't happen" (qplah 1 2 3 4)))
|
||||
(catch [NameError]))
|
||||
(require tests.resources.tlib)
|
||||
(assert (= [1 2 3] (qplah 1 2 3))))
|
||||
|
7
tests/resources/tlib.py
Normal file
7
tests/resources/tlib.py
Normal file
@ -0,0 +1,7 @@
|
||||
from hy.macros import macro
|
||||
from hy import HyList
|
||||
|
||||
|
||||
@macro("qplah")
|
||||
def tmac(tree):
|
||||
return HyList(tree[1:])
|
Loading…
x
Reference in New Issue
Block a user