[pypy-svn] r45173 - pypy/dist/pypy/lang/scheme

jlg at codespeak.net jlg at codespeak.net
Wed Jul 18 10:01:28 CEST 2007


Author: jlg
Date: Wed Jul 18 10:01:27 2007
New Revision: 45173

Modified:
   pypy/dist/pypy/lang/scheme/execution.py
   pypy/dist/pypy/lang/scheme/object.py
Log:
ExecutionContext.bound() -> .bind() seems; W_Pair.to_string() acts different on proper list

Modified: pypy/dist/pypy/lang/scheme/execution.py
==============================================================================
--- pypy/dist/pypy/lang/scheme/execution.py	(original)
+++ pypy/dist/pypy/lang/scheme/execution.py	Wed Jul 18 10:01:27 2007
@@ -128,8 +128,8 @@
         else:
             self.globalscope[name] = Location(obj)
 
-    def bound(self, name):
-        """create new location"""
+    def bind(self, name):
+        """create new empty binding (location)"""
         if self.closure:
             self.scope[name] = Location(None)
         else:

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 10:01:27 2007
@@ -164,10 +164,26 @@
         self.cdr = cdr
 
     def to_string(self):
-        # XXX This should do things differently if (list? self).
         car = self.car.to_string()
-        cdr = self.cdr.to_string()
-        return "(" + car + " . " + cdr + ")"
+        cdr = self.cdr
+        if isinstance(cdr, W_Pair): #proper list
+            return "(" + car + " " + cdr.to_lstring() + ")"
+        elif isinstance(cdr, W_Nil): #one element proper list
+            return "(" + car + ")"
+
+        #dotted list/pair
+        return "(" + car + " . " + cdr.to_string() + ")"
+
+    def to_lstring(self):
+        car = self.car.to_string()
+        cdr = self.cdr
+        if isinstance(cdr, W_Pair): #still proper list
+            return car + " " + cdr.to_lstring()
+        elif isinstance(cdr, W_Nil): #end of proper list
+            return car
+
+        #end proper list with dotted
+        return car + " . " + cdr.to_string()
 
     def eval_tr(self, ctx):
         oper = self.car.eval(ctx)
@@ -640,7 +656,7 @@
             w_def = w_formal.get_car_as_pair()
             name = w_def.car.to_string()
             map_name_expr[name] = w_def.get_cdr_as_pair().car
-            local_ctx.bound(name)
+            local_ctx.bind(name)
             w_formal = w_formal.cdr
 
         map_name_val = {}
@@ -657,14 +673,14 @@
 
 class Quote(W_Macro):
     def call(self, ctx, lst):
-        if not isinstance(lst, W_List):
+        if not isinstance(lst, W_Pair):
             raise SchemeSyntaxError
 
         return lst.car
 
 class Delay(W_Macro):
     def call(self, ctx, lst):
-        if not isinstance(lst, W_List):
+        if not isinstance(lst, W_Pair):
             raise SchemeSyntaxError
 
         return W_Promise(lst.car, ctx)



More information about the Pypy-commit mailing list