Adding in lambdas.
This commit is contained in:
parent
e9d22982af
commit
8a2ba20407
@ -116,6 +116,28 @@ class HyASTCompiler(object):
|
|||||||
lineno=e.start_line,
|
lineno=e.start_line,
|
||||||
col_offset=e.start_column)
|
col_offset=e.start_column)
|
||||||
|
|
||||||
|
@builds("lambda")
|
||||||
|
def compile_lambda_expression(self, expr):
|
||||||
|
expr.pop(0)
|
||||||
|
sig = expr.pop(0)
|
||||||
|
body = expr.pop(0)
|
||||||
|
# assert expr is empty
|
||||||
|
return ast.Lambda(
|
||||||
|
lineno=expr.start_line,
|
||||||
|
col_offset=expr.start_column,
|
||||||
|
args=ast.arguments(args=[
|
||||||
|
ast.Name(arg=str(x), id=str(x),
|
||||||
|
ctx=ast.Param(),
|
||||||
|
lineno=x.start_line,
|
||||||
|
col_offset=x.start_column)
|
||||||
|
for x in sig],
|
||||||
|
vararg=None,
|
||||||
|
kwarg=None,
|
||||||
|
defaults=[],
|
||||||
|
kwonlyargs=[],
|
||||||
|
kw_defaults=[]),
|
||||||
|
body=self.compile(body))
|
||||||
|
|
||||||
@builds("get")
|
@builds("get")
|
||||||
def compile_index_expression(self, expr):
|
def compile_index_expression(self, expr):
|
||||||
expr.pop(0) # index
|
expr.pop(0) # index
|
||||||
|
@ -63,3 +63,9 @@
|
|||||||
"NATIVE: Test that dict access works"
|
"NATIVE: Test that dict access works"
|
||||||
(assert (get {"one" "two"} "one") "two")
|
(assert (get {"one" "two"} "one") "two")
|
||||||
(assert (= (get [1 2 3 4 5] 1) 2)))
|
(assert (= (get [1 2 3 4 5] 1) 2)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn test_lambda []
|
||||||
|
"NATIVE: test lambda operator"
|
||||||
|
(def square (lambda [x] (* x x)))
|
||||||
|
(assert (= 4 (square 2))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user