[pypy-svn] r45193 - in pypy/dist/pypy/lang/scheme: . test

jlg at codespeak.net jlg at codespeak.net
Wed Jul 18 19:36:08 CEST 2007


Author: jlg
Date: Wed Jul 18 19:36:08 2007
New Revision: 45193

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:
quasiquotation code cleanup

Modified: pypy/dist/pypy/lang/scheme/TODO.txt
==============================================================================
--- pypy/dist/pypy/lang/scheme/TODO.txt	(original)
+++ pypy/dist/pypy/lang/scheme/TODO.txt	Wed Jul 18 19:36:08 2007
@@ -20,7 +20,6 @@
 
 Here starts the real fun!
 
-- quasi-quotations: unquote-splicing
 - macros
 - continuations
 - move syntax checking to parsing

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 18 19:36:08 2007
@@ -60,7 +60,7 @@
         return self.name
 
     def __repr__(self):
-        return "<W_symbol " + self.name + ">"
+        return "<W_Symbol " + self.name + ">"
 
 class W_Identifier(W_Symbol):
     def __init__(self, val):
@@ -723,9 +723,12 @@
             w_oper = w_lst.car
             if isinstance(w_oper, W_Identifier):
                 if w_oper.to_string() == "unquote":
+ 
+                    #simply unquote
                     if deep == 1:
                         return w_lst.get_cdr_as_pair().car.eval(ctx)
 
+                    #not first level, look deeper, with lower nesting level
                     if deep > 1:
                         w_unq = self.unquote(ctx,
                                 w_lst.get_cdr_as_pair().car,
@@ -733,19 +736,20 @@
 
                         return W_Pair(w_oper, W_Pair(w_unq, W_Nil()))
 
+                #increment nesting level
                 if w_oper.to_string() == "quasiquote":
                     w_unq = self.unquote(ctx,
                             w_lst.get_cdr_as_pair().car,
                             deep+1)
                     return W_Pair(w_oper, W_Pair(w_unq, W_Nil()))
 
-                if w_oper.to_string() == "unquote-splicing":
-                    if deep > 1:
-                        w_unq = self.unquote(ctx,
-                                w_lst.get_cdr_as_pair().car,
-                                deep-1)
+                #not first level, look deeper, with lower nesting level
+                if deep > 1 and w_oper.to_string() == "unquote-splicing":
+                    w_unq = self.unquote(ctx,
+                            w_lst.get_cdr_as_pair().car,
+                            deep-1)
 
-                        return W_Pair(w_oper, W_Pair(w_unq, W_Nil()))
+                    return W_Pair(w_oper, W_Pair(w_unq, W_Nil()))
 
             #for unquote-splice we need to check one level earlier
             #cond = if we have w_oper = (unquote-splice <sexpr>)

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	Wed Jul 18 19:36:08 2007
@@ -580,6 +580,8 @@
                                       (quote (unquote name)))))""")
     assert w_res.to_string() == "(list a (quote a))"
 
+    py.test.raises(UnboundVariable, eval_noctx, "`(,,(+ 1 2))")
+
 def test_quasiquote_nested():
     w_res = eval_noctx("""
                 (quasiquote
@@ -609,6 +611,7 @@
 def test_quasiquote_splicing():
     w_res = eval_noctx("""`(1 2 ,@(list 3 4) 5 6)""")
     assert w_res.to_string() == "(1 2 3 4 5 6)"
+    py.test.raises(UnboundVariable, eval_noctx, "`(,@(list 1 ,@(list 2 3)))")
 
     w_res = eval_noctx("""`(1 2 ,@(list 3 4) . ,(+ 2 3))""")
     assert w_res.to_string() == "(1 2 3 4 . 5)"
@@ -618,4 +621,6 @@
 
 def test_quasiquote_splicing2():
     w_res = eval_noctx("""`(1 `(2 ,@(list ,@(list 3 4) 5 6 ,(+ 0 7))))""")
-    assert w_res.to_string() == "(1 (quasiquote (2 (unquote-splicing (list 3 4 5 6 7)))))"
+    assert w_res.to_string() == \
+        "(1 (quasiquote (2 (unquote-splicing (list 3 4 5 6 7)))))"
+



More information about the Pypy-commit mailing list