Allow fn to have no body

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2013-04-19 18:31:32 -07:00
parent aadf47ed99
commit 74ea8fe5e5
3 changed files with 6 additions and 2 deletions

View File

@ -1027,7 +1027,7 @@ class HyASTCompiler(object):
col_offset=expr.start_column)
@builds("fn")
@checkargs(min=2)
@checkargs(min=1)
def compile_fn_expression(self, expression):
expression.pop(0) # fn

View File

@ -300,6 +300,8 @@ def test_ast_anon_fns_basics():
""" Ensure anon fns work. """
code = hy_compile(tokenize("(fn (x) (* x x))")).body[0]
assert type(code) == ast.FunctionDef
code = hy_compile(tokenize("(fn (x))")).body[0]
cant_compile("(fn)")
def test_ast_non_decoratable():

View File

@ -474,7 +474,9 @@
(defn test-fn-return []
"NATIVE: test function return"
(setv fn-test ((fn [] (fn [] (+ 1 1)))))
(assert (= (fn-test) 2)))
(assert (= (fn-test) 2))
(setv fn-test (fn []))
(assert (= (fn-test) None)))
(defn test-let []