[pypy-svn] r45813 - in pypy/dist/pypy/lang/scheme: . test
jlg at codespeak.net
jlg at codespeak.net
Fri Aug 17 15:06:56 CEST 2007
Author: jlg
Date: Fri Aug 17 15:06:56 2007
New Revision: 45813
Modified:
pypy/dist/pypy/lang/scheme/TODO.txt
pypy/dist/pypy/lang/scheme/object.py
pypy/dist/pypy/lang/scheme/test/test_eval.py
Log:
apply procedure introduced
Modified: pypy/dist/pypy/lang/scheme/TODO.txt
==============================================================================
--- pypy/dist/pypy/lang/scheme/TODO.txt (original)
+++ pypy/dist/pypy/lang/scheme/TODO.txt Fri Aug 17 15:06:56 2007
@@ -23,7 +23,9 @@
- macros *are* not first-class objects
- input/output operations
-- missing datatypes: chars, strings, vectors
+- missing datatypes: chars, vectors
+- datatypes manipulation procedures
+
- switch to byte-code generation + eval instead of evaluating AST
- random code stress test
Modified: pypy/dist/pypy/lang/scheme/object.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/object.py (original)
+++ pypy/dist/pypy/lang/scheme/object.py Fri Aug 17 15:06:56 2007
@@ -644,6 +644,22 @@
w_pair.cdr = w_obj
return w_undefined
+class Apply(W_Procedure):
+ _symbol_name = "apply"
+
+ def procedure_tr(self, ctx, lst):
+ if len(lst) != 2:
+ raise WrongArgsNumber
+
+ (w_procedure, w_lst) = lst
+ if not isinstance(w_procedure, W_Procedure):
+ raise WrongArgType(w_procedure, "Procedure")
+
+ if not isinstance(w_lst, W_List):
+ raise WrongArgType(w_lst, "List")
+
+ return w_procedure.call_tr(ctx, w_lst)
+
class Quit(W_Procedure):
_symbol_name = "quit"
@@ -693,7 +709,7 @@
w_obj = lst[0]
if not isinstance(w_obj, W_Number):
- raise WrongArgType(w_obj, 'Number')
+ raise WrongArgType(w_obj, "Number")
return W_Boolean(self.predicate(w_obj))
@@ -1018,7 +1034,6 @@
map_name_val = {}
w_name_val = DictWrapper(map_name_val)
for (name, expr) in map_name_expr.items():
- #map_name_val[name] = expr.eval(local_ctx)
map_name_val[name] = expr.eval_cf(local_ctx, self,
map_name_symb[name],
[body, w_name_symb, w_name_val], 3)
@@ -1576,7 +1591,6 @@
class ContinuationFrame(object):
def __init__(self, caller, continuation, evaluated_args = [], enum=0):
- #assert hasattr(caller, "continue_tr")
self.caller = caller
assert isinstance(continuation, W_Root)
self.continuation = continuation
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 Fri Aug 17 15:06:56 2007
@@ -723,3 +723,19 @@
assert eval_(ctx, """(eq? (lambda () 1)
(lambda () 2))""").to_boolean() is False
+def test_apply():
+ ctx = ExecutionContext()
+ assert eval_(ctx, "(apply + (list 3 4))").to_number() == 7
+
+ eval_(ctx, """(define compose
+ (lambda (f g)
+ (lambda args
+ (f (apply g args)))))""")
+ w_result = eval_(ctx, "((compose (lambda (x) (* x x)) +) 3 5)")
+ assert w_result.to_number() == 64
+
+ assert eval_(ctx, "(apply + '())").to_number() == 0
+ py.test.raises(WrongArgsNumber, eval_, ctx, "(apply 1)")
+ py.test.raises(WrongArgType, eval_, ctx, "(apply 1 '(1))")
+ py.test.raises(WrongArgType, eval_, ctx, "(apply + 42)")
+
More information about the Pypy-commit
mailing list