Allow variable without value in `let' declaration

Fixes issue #138

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2013-04-19 19:20:09 -07:00
parent aadf47ed99
commit 07860b5ce6
2 changed files with 10 additions and 4 deletions

View File

@ -133,12 +133,17 @@ def rest_macro(tree):
@macro("let") @macro("let")
def let_macro(tree): def let_macro(tree):
tree.pop(0) # "let" tree.pop(0) # "let"
ret = tree.pop(0) # vars variables = tree.pop(0)
# tree is now the body # tree is now the body
expr = HyExpression([HySymbol("fn"), HyList([])]) expr = HyExpression([HySymbol("fn"), HyList([])])
for var in ret: for var in variables:
expr.append(HyExpression([HySymbol("setf"), var[0], var[1]])) if isinstance(var, list):
expr.append(HyExpression([HySymbol("setf"),
var[0], var[1]]))
else:
expr.append(HyExpression([HySymbol("setf"),
var, HySymbol("None")]))
for stmt in tree: for stmt in tree:
expr.append(stmt) expr.append(stmt)

View File

@ -479,7 +479,8 @@
(defn test-let [] (defn test-let []
"NATIVE: test let works rightish" "NATIVE: test let works rightish"
(assert (= (let [[x 1] [y 2] [z 3]] (+ x y z)) 6))) (assert (= (let [[x 1] [y 2] [z 3]] (+ x y z)) 6))
(assert (= (let [[x 1] a [y 2] b] (if a 1 2)) 2)))
(defn test-if-mangler [] (defn test-if-mangler []