Implementing `let'
This commit is contained in:
parent
9178d541fd
commit
7abc472336
@ -114,3 +114,19 @@ def rest_macro(tree):
|
||||
return HyExpression([HySymbol('slice'),
|
||||
ret,
|
||||
HyInteger(1)])
|
||||
|
||||
|
||||
@macro("let")
|
||||
def let_macro(tree):
|
||||
tree.pop(0) # "let"
|
||||
ret = tree.pop(0) # vars
|
||||
# tree is now the body
|
||||
expr = HyExpression([HySymbol("fn"), HyList([])])
|
||||
|
||||
for var in ret:
|
||||
expr.append(HyExpression([HySymbol("setf"), var[0], var[1]]))
|
||||
|
||||
for stmt in tree:
|
||||
expr.append(stmt)
|
||||
|
||||
return HyExpression([expr])
|
||||
|
@ -294,6 +294,11 @@
|
||||
(assert (= (fn-test) 2)))
|
||||
|
||||
|
||||
(defn test-let []
|
||||
"NATIVE: test let works rightish"
|
||||
(assert (= (let [[x 1] [y 2] [z 3]] (+ x y z)) 6)))
|
||||
|
||||
|
||||
; FEATURE: native hy-eval
|
||||
;
|
||||
; - related to bug #64
|
||||
|
Loading…
x
Reference in New Issue
Block a user