Collection.st
changeset 44 b262907c93ea
parent 34 c81f1ac4ad50
child 54 06dbdeeed4f9
--- a/Collection.st	Sun Jan 16 04:38:33 1994 +0100
+++ b/Collection.st	Sun Jan 16 04:47:41 1994 +0100
@@ -24,7 +24,7 @@
 
 Abstract superclass for all collections
 
-$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.8 1994-01-08 16:37:20 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.9 1994-01-16 03:40:14 claus Exp $
 '!
 
 !Collection class methodsFor:'initialization'!
@@ -552,9 +552,15 @@
 !
 
 printOn:aStream
-    |tooMany firstOne noMore|
+    |limit firstOne noMore s|
 
-    tooMany := aStream position + self maxPrint.
+    thisContext isRecursive ifTrue:[
+        Transcript showCr:'Error: printOn: of self referencing collection.'.
+        aStream nextPutAll:'#("recursive")'.
+        ^ self
+    ].
+
+    limit := self maxPrint.
     aStream nextPutAll:self class name.
     aStream nextPut:$(.
     firstOne := true.
@@ -562,19 +568,25 @@
     self do:[:element |
         noMore ifFalse:[
             firstOne ifFalse:[
-                aStream nextPut:(Character space)
+                aStream space
             ] ifTrue:[
                 firstOne := false
             ].
-            (aStream position > tooMany) ifTrue:[
+            (limit <= 0) ifTrue:[
                 aStream nextPutAll:'...etc...)'.
                 noMore := true
             ] ifFalse:[
-                element printOn:aStream
+                s := element printString.
+                aStream nextPutAll:s.
+                limit := limit - s size
             ]
         ].
     ].
     aStream nextPut:$)
+
+    "#(1 2 3 'hello' $a) printOn:Transcript"
+    "(Dictionary new at:#hello put:'world'; yourself) printOn:Transcript"
+
 !
 
 storeOn:aStream
@@ -583,16 +595,26 @@
 
     |isEmpty|
 
-    aStream nextPutAll:'(('.
+    thisContext isRecursive ifTrue:[
+        Transcript showCr:'Error: printOn: of self referencing collection.'.
+        aStream nextPutAll:'#("recursive")'.
+        ^ self
+    ].
+
+    aStream nextPutAll:'('.
     aStream nextPutAll:(self class name).
-    aStream nextPutAll:' new)'.
+    aStream nextPutAll:' new'.
     isEmpty := true.
     self do:[:element |
-        aStream nextPutAll:' add:('.
+        aStream nextPutAll:' add:'.
         element storeOn:aStream.
-        aStream nextPutAll:');'.
+        aStream nextPutAll:';'.
         isEmpty := false
     ].
     isEmpty ifFalse:[aStream nextPutAll:' yourself'].
     aStream nextPut:$)
+
+    "OrderedCollection new storeOn:Transcript"
+    "(1 to:10) storeOn:Transcript"
+    "(Set new add:1; add:'hello'; yourself) storeOn:Transcript"
 ! !