[pypy-svn] r44740 - in pypy/dist/pypy/lang/scheme: . test
jlg at codespeak.net
jlg at codespeak.net
Thu Jul 5 16:02:01 CEST 2007
Author: jlg
Date: Thu Jul 5 16:02:00 2007
New Revision: 44740
Modified:
pypy/dist/pypy/lang/scheme/object.py
pypy/dist/pypy/lang/scheme/test/test_eval.py
Log:
(lambda x <body>) takes any number of arguments, x is newly allocated list of arguments
Modified: pypy/dist/pypy/lang/scheme/object.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/object.py (original)
+++ pypy/dist/pypy/lang/scheme/object.py Thu Jul 5 16:02:00 2007
@@ -164,10 +164,14 @@
self.args = []
arg = args
while not isinstance(arg, W_Nil):
- assert isinstance(arg.car, W_Identifier)
- #list of argument names, not evaluated
- self.args.append(arg.car.to_string())
- arg = arg.cdr
+ if isinstance(arg, W_Identifier):
+ self.args.append([arg.to_string()])
+ break
+ else:
+ assert isinstance(arg.car, W_Identifier)
+ #list of argument names, not evaluated
+ self.args.append(arg.car.to_string())
+ arg = arg.cdr
self.body = body
self.pname = pname
@@ -177,16 +181,24 @@
return "#<procedure %s>" % (self.pname,)
def procedure(self, ctx, lst):
- #ctx is a caller context, which is hoyfully ignored
- if len(lst) != len(self.args):
- raise "Wrong argument count"
+ #ctx is a caller context, which is joyfully ignored
+
+ #if len(lst) != len(self.args):
+ # raise "Wrong argument count"
local_ctx = self.closure.copy()
#set lambda arguments
- vars = zip(self.args, lst)
- for (name, val) in vars:
- local_ctx.put(name, val)
+ for idx in range(len(self.args)):
+ name = self.args[idx]
+ if isinstance(name, list):
+ local_ctx.put(name[0], plst2lst(lst[idx:]))
+ else:
+ local_ctx.put(name, lst[idx])
+
+ #vars = zip(self.args, lst)
+ #for (name, val) in vars:
+ # local_ctx.put(name, val)
body_expression = self.body
body_result = None
@@ -196,6 +208,15 @@
return body_result # self.body.eval(local_ctx)
+def plst2lst(plst):
+ """coverts python list() of W_Root into W_Pair scheme list"""
+ w_cdr = W_Nil()
+ plst.reverse()
+ for w_obj in plst:
+ w_cdr = W_Pair(w_obj, w_cdr)
+
+ return w_cdr
+
##
# operations
##
@@ -378,7 +399,7 @@
raise "Unbound"
def set(self, name, obj):
- """update existing location or create new location new"""
+ """update existing location or create new location"""
if self.closure:
loc = self.scope.get(name, None)
else:
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 Thu Jul 5 16:02:00 2007
@@ -232,3 +232,11 @@
assert w_result.to_number() == 43
assert ctx.get("x") is None
+def test_lambda_lstarg():
+ ctx = ExecutionContext()
+ w_result = eval_expr(ctx, """((lambda x x) 1 2 3)""")
+ assert isinstance(w_result, W_Pair)
+ assert w_result.car.to_number() == 1
+ assert w_result.cdr.car.to_number() == 2
+ assert w_result.cdr.cdr.car.to_number() == 3
+
More information about the Pypy-commit
mailing list