[pypy-svn] r44723 - in pypy/dist/pypy/lang/scheme: . test
jlg at codespeak.net
jlg at codespeak.net
Wed Jul 4 15:11:05 CEST 2007
Author: jlg
Date: Wed Jul 4 15:11:05 2007
New Revision: 44723
Modified:
pypy/dist/pypy/lang/scheme/object.py
pypy/dist/pypy/lang/scheme/test/test_object.py
Log:
lambda is more like W_Procedure now
Modified: pypy/dist/pypy/lang/scheme/object.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/object.py (original)
+++ pypy/dist/pypy/lang/scheme/object.py Wed Jul 4 15:11:05 2007
@@ -161,31 +161,35 @@
class W_Lambda(W_Procedure):
def __init__(self, args, body, pname="#f"):
- self.args = args
+ self.args = []
+ arg = args
+ while not isinstance(arg, W_Nil):
+ #list of argumen names, not evaluated
+ self.args.append(arg.car)
+ arg = arg.cdr
+
self.body = body
self.pname = pname
def to_string(self):
return "#<procedure %s>" % (self.pname,)
- 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
+ def procedure(self, ctx, lst):
+ if len(lst) != len(self.args):
+ #wrong argument count
+ raise
+
+ local_ctx = ctx.copy()
+ vars = zip(self.args, lst)
+ for name_val in vars:
+ assert isinstance(name_val[0], W_Identifier)
+ local_ctx.put(name_val[0].to_string(), name_val[1])
- return self.body.eval(my_ctx)
+ return self.body.eval(local_ctx)
##
# operations
##
-
class ListOper(W_Procedure):
def procedure(self, ctx, lst):
acc = None
Modified: pypy/dist/pypy/lang/scheme/test/test_object.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/test/test_object.py (original)
+++ pypy/dist/pypy/lang/scheme/test/test_object.py Wed Jul 4 15:11:05 2007
@@ -1,6 +1,5 @@
import py
from pypy.lang.scheme.object import *
-from pypy.lang.scheme.operation import *
def test_false():
w_false = W_Boolean(False)
More information about the pypy-svn
mailing list