[pypy-svn] r44696 - in pypy/dist/pypy/lang/scheme: . test
jlg at codespeak.net
jlg at codespeak.net
Tue Jul 3 14:41:44 CEST 2007
Author: jlg
Date: Tue Jul 3 14:41:43 2007
New Revision: 44696
Modified:
pypy/dist/pypy/lang/scheme/object.py
pypy/dist/pypy/lang/scheme/test/test_eval.py
Log:
trivial lambdas with arguments works
Modified: pypy/dist/pypy/lang/scheme/object.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/object.py (original)
+++ pypy/dist/pypy/lang/scheme/object.py Tue Jul 3 14:41:43 2007
@@ -128,6 +128,20 @@
self.args = args
self.body = body
+ def eval(self, ctx, lst):
+ name = self.args
+ val = lst
+ my_ctx = ctx.copy()
+ while not isinstance(name, W_Nil):
+ assert isinstance(name.car, W_Identifier)
+ w_val = val.car.eval(ctx)
+ my_ctx.put(name.car.to_string(), w_val)
+
+ val = val.cdr
+ name = name.cdr
+
+ return self.body.eval(my_ctx)
+
##
# operations
##
Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/test/test_eval.py (original)
+++ pypy/dist/pypy/lang/scheme/test/test_eval.py Tue Jul 3 14:41:43 2007
@@ -144,8 +144,21 @@
w_cddr = eval_noctx("(cdr (cdr (cons 1 (cons 2 3))))")
assert w_cddr.to_number() == 3
-def test_lambda_definition():
+def test_lambda_noargs():
ctx = ExecutionContext()
w_lambda = eval_expr(ctx, "(lambda () 12)")
assert isinstance(w_lambda, W_Lambda)
+ ctx.put("f1", w_lambda)
+ w_result = eval_expr(ctx, "(f1)")
+ assert isinstance(w_result, W_Fixnum)
+ assert w_result.to_number() == 12
+
+def test_lambda_args():
+ ctx = ExecutionContext()
+ eval_expr(ctx, "(define f1 (lambda (n) n))")
+
+ w_result = eval_expr(ctx, "(f1 42)")
+ assert isinstance(w_result, W_Fixnum)
+ assert w_result.to_number() == 42
+
More information about the Pypy-commit
mailing list