another example
authorClaus Gittinger <cg@exept.de>
Fri, 10 Jan 1997 20:17:06 +0100
changeset 360 c5e6039033e7
parent 359 6fdd7d3119a8
child 361 765fe20a26d1
another example
Plug.st
--- a/Plug.st	Fri Jan 10 19:16:44 1997 +0100
+++ b/Plug.st	Fri Jan 10 20:17:06 1997 +0100
@@ -69,6 +69,21 @@
     plug foo:'some argument'
                                                                         [exEnd]
 
+  using a plug as a generator (simulates a readStream):
+                                                                        [exBegin]
+    |generator num|
+
+    num := 0.
+    generator := Plug new.
+    generator respondTo:#next
+                   with:[num := num + 1. num].
+    generator respondTo:#atEnd
+                   with:[false].
+
+    10 timesRepeat:[
+        Transcript showCR:(generator next)
+    ]
+                                                                        [exEnd]
 
   simulating ``instance variables'':
   (actually, this is somewhat expensive - the contexts locals are used for them ...)
@@ -197,5 +212,5 @@
 !Plug class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/Plug.st,v 1.13 1996-05-18 15:37:08 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/Plug.st,v 1.14 1997-01-10 19:17:06 cg Exp $'
 ! !