1378
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2003 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libbasic2' }"
|
|
13 |
|
|
14 |
Stream subclass:#ConsStream
|
|
15 |
instanceVariableNames:'list'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Collections-Linked'
|
|
19 |
!
|
|
20 |
|
|
21 |
!ConsStream class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2003 by eXept Software AG
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
|
37 |
documentation
|
|
38 |
"
|
|
39 |
A stream on a list (of conses)
|
|
40 |
Conses are not heavily used by Smalltalk (actually: not at all).
|
|
41 |
Consider this a demo class.
|
|
42 |
|
|
43 |
[author:]
|
2661
|
44 |
Claus Gittinger (Dec 2003)
|
1378
|
45 |
|
|
46 |
[see also:]
|
|
47 |
|
|
48 |
"
|
|
49 |
!
|
|
50 |
|
|
51 |
examples
|
|
52 |
"
|
|
53 |
[exBegin]
|
|
54 |
|list s|
|
|
55 |
|
|
56 |
list := Cons fromArray:#(1 2 3 4).
|
|
57 |
s := list readStream.
|
|
58 |
[s atEnd] whileFalse:[
|
|
59 |
Transcript showCR:(s next).
|
|
60 |
].
|
|
61 |
[exEnd]
|
|
62 |
[exBegin]
|
|
63 |
|gen allNumbers s|
|
|
64 |
|
|
65 |
gen := [:n | LazyCons car:n cdr:[ gen value:n+1 ]].
|
|
66 |
allNumbers := gen value:1.
|
|
67 |
|
|
68 |
s := allNumbers readStream.
|
|
69 |
100 timesRepeat:[
|
|
70 |
Transcript showCR:(s next).
|
|
71 |
].
|
|
72 |
[exEnd]
|
|
73 |
"
|
|
74 |
! !
|
|
75 |
|
|
76 |
!ConsStream class methodsFor:'instance creation'!
|
|
77 |
|
|
78 |
on:aCons
|
|
79 |
^ self basicNew list:aCons
|
|
80 |
! !
|
|
81 |
|
|
82 |
!ConsStream methodsFor:'accessing'!
|
|
83 |
|
|
84 |
list:something
|
|
85 |
list := something.
|
|
86 |
! !
|
|
87 |
|
|
88 |
!ConsStream methodsFor:'reading'!
|
|
89 |
|
|
90 |
atEnd
|
|
91 |
^ list isNil
|
|
92 |
!
|
|
93 |
|
|
94 |
next
|
|
95 |
|rslt|
|
|
96 |
|
|
97 |
list isNil ifTrue:[
|
1482
|
98 |
^ self pastEndRead
|
1378
|
99 |
].
|
|
100 |
rslt := list car.
|
|
101 |
list := list cdr.
|
|
102 |
^ rslt
|
|
103 |
! !
|
|
104 |
|
|
105 |
!ConsStream class methodsFor:'documentation'!
|
|
106 |
|
|
107 |
version
|
2661
|
108 |
^ '$Header: /cvs/stx/stx/libbasic2/ConsStream.st,v 1.4 2011-09-27 09:42:44 cg Exp $'
|
|
109 |
!
|
|
110 |
|
|
111 |
version_CVS
|
|
112 |
^ '$Header: /cvs/stx/stx/libbasic2/ConsStream.st,v 1.4 2011-09-27 09:42:44 cg Exp $'
|
1378
|
113 |
! !
|