author | Claus Gittinger <cg@exept.de> |
Tue, 18 Dec 2018 12:52:15 +0100 | |
changeset 4777 | b22943151ce0 |
parent 4773 | 9a9b8a439b6d |
child 4797 | ea7ce61a8957 |
permissions | -rw-r--r-- |
2337
755696d72648
comment/format in: #asSoundexCode
Claus Gittinger <cg@exept.de>
parents:
2303
diff
changeset
|
1 |
"{ Package: 'stx:libbasic2' }"! |
1668 | 2 |
|
4381 | 3 |
!ArithmeticValue methodsFor:'converting'! |
4 |
||
5 |
asQDouble |
|
6 |
"return a QDouble with same value" |
|
7 |
||
4480 | 8 |
^ QDouble fromFloat:self asFloat |
4381 | 9 |
|
10 |
" |
|
11 |
123 asQDouble |
|
4480 | 12 |
(Fraction basicNew setNumerator:246 denominator:2) asQDouble |
13 |
123 asLongFloat asQDouble |
|
14 |
123 asLargeFloat asQDouble |
|
4381 | 15 |
" |
16 |
||
17 |
"Created: / 13-06-2017 / 16:48:24 / cg" |
|
4480 | 18 |
"Modified (comment): / 25-07-2017 / 16:06:19 / cg" |
4381 | 19 |
! ! |
20 |
||
4379
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
21 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
22 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
23 |
differenceFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
24 |
"aQDouble does not know how to subtract the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
25 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
26 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
27 |
^ aQDouble retry:#- coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
28 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
29 |
"Created: / 13-06-2017 / 08:55:38 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
30 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
31 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
32 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
33 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
34 |
equalFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
35 |
"aQDouble does not know how to compare to the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
36 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
37 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
38 |
^ aQDouble retry:#= coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
39 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
40 |
"Created: / 13-06-2017 / 08:55:30 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
41 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
42 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
43 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
44 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
45 |
lessFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
46 |
"aQDouble does not know how to compare to the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
47 |
Return true if aQDouble < self. |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
48 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
49 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
50 |
^ aQDouble retry:#< coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
51 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
52 |
"Created: / 13-06-2017 / 08:55:20 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
53 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
54 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
55 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
56 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
57 |
productFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
58 |
"aQDouble does not know how to multiply the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
59 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
60 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
61 |
^ aQDouble retry:#* coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
62 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
63 |
"Created: / 13-06-2017 / 08:55:07 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
64 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
65 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
66 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
67 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
68 |
quotientFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
69 |
"aQDouble does not know how to divide by the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
70 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
71 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
72 |
^ aQDouble retry:#/ coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
73 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
74 |
"Created: / 13-06-2017 / 08:54:55 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
75 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
76 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
77 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
78 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
79 |
remainderFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
80 |
"aQDouble does not know how to compute the remainder with the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
81 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
82 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
83 |
^ aQDouble retry:#rem: coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
84 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
85 |
"Created: / 13-06-2017 / 08:54:47 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
86 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
87 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
88 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
89 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
90 |
sumFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
91 |
"aQDouble does not know how to add the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
92 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
93 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
94 |
^ aQDouble retry:#+ coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
95 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
96 |
"Created: / 13-06-2017 / 08:54:27 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
97 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
98 |
|
4448 | 99 |
!Block methodsFor:'Compatibility-Dolphin'! |
100 |
||
101 |
deferredValue |
|
102 |
"Dolphin compatibility method - do not use in new code. |
|
103 |
Dolphin's alias for futureValue" |
|
104 |
||
105 |
^ Future new block:self |
|
106 |
||
107 |
"Modified: / 04-10-2011 / 14:56:27 / cg" |
|
108 |
! ! |
|
109 |
||
110 |
!Block methodsFor:'Compatibility-Dolphin'! |
|
111 |
||
112 |
deferredValueAt:priority |
|
113 |
"Dolphin compatibility method - do not use in new code. |
|
114 |
Dolphin's alias for futureValue" |
|
115 |
||
116 |
^ Future new |
|
117 |
priority:priority block:self |
|
118 |
||
119 |
"Created: / 04-10-2011 / 14:55:56 / cg" |
|
120 |
! ! |
|
121 |
||
122 |
!Block methodsFor:'parallel evaluation'! |
|
123 |
||
124 |
futureValue |
|
125 |
"Fork a synchronised evaluation of myself. |
|
126 |
Starts the evaluation in parallel now, but synchronizes |
|
127 |
any access to wait until the result is computed." |
|
128 |
||
129 |
^ Future new block:self |
|
130 |
! ! |
|
131 |
||
132 |
!Block methodsFor:'parallel evaluation'! |
|
133 |
||
134 |
futureValue:aValue |
|
135 |
"Fork a synchronised evaluation of myself. |
|
136 |
Starts the evaluation in parallel now, but synchronizes |
|
137 |
any access to wait until the result is computed." |
|
138 |
||
139 |
^ Future new block:self value:aValue |
|
140 |
! ! |
|
141 |
||
142 |
!Block methodsFor:'parallel evaluation'! |
|
143 |
||
144 |
futureValue:aValue value:anotherValue |
|
145 |
"Fork a synchronised evaluation of myself. |
|
146 |
Starts the evaluation in parallel now, but synchronizes |
|
147 |
any access to wait until the result is computed." |
|
148 |
||
149 |
^ Future new |
|
150 |
block:self |
|
151 |
value:aValue |
|
152 |
value:anotherValue |
|
153 |
! ! |
|
154 |
||
155 |
!Block methodsFor:'parallel evaluation'! |
|
156 |
||
157 |
futureValue:aValue value:anotherValue value:bValue |
|
158 |
"Fork a synchronised evaluation of myself. |
|
159 |
Starts the evaluation in parallel now, but synchronizes |
|
160 |
any access to wait until the result is computed." |
|
161 |
||
162 |
^ Future new |
|
163 |
block:self |
|
164 |
value:aValue |
|
165 |
value:anotherValue |
|
166 |
value:bValue |
|
167 |
! ! |
|
168 |
||
169 |
!Block methodsFor:'parallel evaluation'! |
|
170 |
||
171 |
futureValueWithArguments:anArray |
|
172 |
"Fork a synchronised evaluation of myself. |
|
173 |
Starts the evaluation in parallel now, but synchronizes |
|
174 |
any access to wait until the result is computed." |
|
175 |
||
176 |
^ Future new |
|
177 |
block:self |
|
178 |
valueWithArguments:anArray |
|
179 |
||
180 |
"Modified (format): / 04-10-2011 / 14:55:40 / cg" |
|
181 |
! ! |
|
182 |
||
183 |
!Block methodsFor:'parallel evaluation'! |
|
184 |
||
185 |
lazyValue |
|
186 |
"Fork a synchronised evaluation of myself. Only starts |
|
187 |
the evaluation when the result is requested." |
|
188 |
||
189 |
^ Lazy new block:self |
|
190 |
! ! |
|
191 |
||
192 |
!Block methodsFor:'parallel evaluation'! |
|
193 |
||
194 |
lazyValue:aValue |
|
195 |
"Fork a synchronised evaluation of myself. Only starts |
|
196 |
the evaluation when the result is requested." |
|
197 |
||
198 |
^ Lazy new block:self value:aValue |
|
199 |
! ! |
|
200 |
||
201 |
!Block methodsFor:'parallel evaluation'! |
|
202 |
||
203 |
lazyValue:aValue value:anotherValue |
|
204 |
"Fork a synchronised evaluation of myself. Only starts |
|
205 |
the evaluation when the result is requested." |
|
206 |
||
207 |
^ Lazy new |
|
208 |
block:self |
|
209 |
value:aValue |
|
210 |
value:anotherValue |
|
211 |
! ! |
|
212 |
||
213 |
!Block methodsFor:'parallel evaluation'! |
|
214 |
||
215 |
lazyValue:aValue value:anotherValue value:bValue |
|
216 |
"Fork a synchronised evaluation of myself. Only starts |
|
217 |
the evaluation when the result is requested." |
|
218 |
||
219 |
^ Lazy new |
|
220 |
block:self |
|
221 |
value:aValue |
|
222 |
value:anotherValue |
|
223 |
value:bValue |
|
224 |
! ! |
|
225 |
||
226 |
!Block methodsFor:'parallel evaluation'! |
|
227 |
||
228 |
lazyValueWithArguments:anArray |
|
229 |
"Fork a synchronised evaluation of myself. Only starts |
|
230 |
the evaluation when the result is requested." |
|
231 |
||
232 |
^ Lazy new block:self valueWithArguments:anArray |
|
233 |
! ! |
|
234 |
||
235 |
!Block methodsFor:'process creation'! |
|
236 |
||
237 |
promise |
|
238 |
"create a promise on the receiver. The promise will evaluate the |
|
239 |
receiver and promise to return the value with the #value message. |
|
240 |
The evaluation will be performed as a separate process. |
|
241 |
Asking the promise for its value will either block the asking process |
|
242 |
(if the evaluation has not yet been finished) or return the value |
|
243 |
immediately." |
|
244 |
||
245 |
^ Promise value:self |
|
246 |
||
247 |
" |
|
248 |
|p| |
|
249 |
||
250 |
p := [1000 factorial] promise. |
|
251 |
'do something else ...'. |
|
252 |
p value |
|
253 |
" |
|
254 |
! ! |
|
255 |
||
256 |
!Block methodsFor:'process creation'! |
|
257 |
||
258 |
promiseAt:prio |
|
259 |
"create a promise on the receiver. The promise will evaluate the |
|
260 |
receiver and promise to return the value with the #value message. |
|
261 |
The evaluation will be performed as a separate process running at prio. |
|
262 |
Asking the promise for its value will either block the asking process |
|
263 |
(if the evaluation has not yet been finished) or return the value |
|
264 |
immediately." |
|
265 |
||
266 |
^ Promise value:self priority:prio |
|
267 |
! ! |
|
268 |
||
2288 | 269 |
!CharacterArray methodsFor:'matching - phonetic'! |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
270 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
271 |
asKoelnerPhoneticCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
272 |
"return a koelner phonetic code. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
273 |
The koelnerPhonetic code is for the german language what the soundex code is for english; |
2303 | 274 |
it returns simular strings for similar sounding words. |
275 |
There are some differences to soundex, though: |
|
276 |
its length is not limited to 4, but depends on the length of the original string; |
|
277 |
it does not start with the first character of the input. |
|
2288 | 278 |
|
279 |
Caveat: this phonetic code is especially suited for german words. |
|
2303 | 280 |
Please have a look at the other phonetic comparison operators found |
281 |
in PhoneticStringUtilities." |
|
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
282 |
|
2303 | 283 |
^ PhoneticStringUtilities koelnerPhoneticCodeOf:self |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
284 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
285 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
286 |
#( |
3715 | 287 |
'Müller' |
2303 | 288 |
'Miller' |
289 |
'Mueller' |
|
3715 | 290 |
'Mühler' |
291 |
'Mühlherr' |
|
292 |
'Mülherr' |
|
2303 | 293 |
'Myler' |
294 |
'Millar' |
|
295 |
'Myller' |
|
3715 | 296 |
'Müllar' |
297 |
'Müler' |
|
2303 | 298 |
'Muehler' |
3715 | 299 |
'Mülller' |
300 |
'Müllerr' |
|
2303 | 301 |
'Muehlherr' |
302 |
'Muellar' |
|
303 |
'Mueler' |
|
3715 | 304 |
'Mülleer' |
2303 | 305 |
'Mueller' |
3715 | 306 |
'Nüller' |
2303 | 307 |
'Nyller' |
308 |
'Niler' |
|
309 |
'Czerny' |
|
310 |
'Tscherny' |
|
311 |
'Czernie' |
|
312 |
'Tschernie' |
|
313 |
'Schernie' |
|
314 |
'Scherny' |
|
315 |
'Scherno' |
|
316 |
'Czerne' |
|
317 |
'Zerny' |
|
318 |
'Tzernie' |
|
319 |
'Breschnew' |
|
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
320 |
) do:[:w | |
2303 | 321 |
Transcript show:w; show:'->'; showCR:(w asKoelnerPhoneticCode) |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
322 |
]. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
323 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
324 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
325 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
326 |
'Breschnew' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
327 |
'Breschnew' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
328 |
'Breschneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
329 |
'Braeschneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
330 |
'Braessneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
331 |
'Pressneff' asKoelnerPhoneticCode -> '17863' |
3715 | 332 |
'Presznäph' asKoelnerPhoneticCode -> '17863' |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
333 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
334 |
! ! |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
335 |
|
2288 | 336 |
!CharacterArray methodsFor:'matching - phonetic'! |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
337 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
338 |
asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
339 |
"return a soundex phonetic code or nil. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
340 |
Soundex returns similar codes for similar sounding words, making it a useful |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
341 |
tool when searching for words where the correct spelling is unknown. |
4190 | 342 |
(read Knuth or search the web if you don't know what a soundex code is). |
2288 | 343 |
|
2337
755696d72648
comment/format in: #asSoundexCode
Claus Gittinger <cg@exept.de>
parents:
2303
diff
changeset
|
344 |
Caveat: 'similar sounding words' means: 'similar sounding in ENGLISH' |
4190 | 345 |
Please have a look at the other phonetic comparison operators found |
346 |
in PhoneticStringUtilities." |
|
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
347 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
348 |
^ PhoneticStringUtilities soundexCodeOf:self |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
349 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
350 |
" |
2303 | 351 |
'claus' asSoundexCode |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
352 |
'clause' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
353 |
'close' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
354 |
'smalltalk' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
355 |
'smaltalk' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
356 |
'smaltak' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
357 |
'smaltok' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
358 |
'smoltok' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
359 |
'aa' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
360 |
'by' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
361 |
'bab' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
362 |
'bob' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
363 |
'bop' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
364 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
365 |
! ! |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
366 |
|
2241 | 367 |
!CharacterArray methodsFor:'printing & storing'! |
368 |
||
2303 | 369 |
printf:args |
370 |
"Format and print the receiver with <args> formatted in C style, |
|
2295 | 371 |
as specified in the Unix C-language manual page for printf(3). |
3114 | 372 |
Return the resulting string (i.e actually, this is more like an sprintf). |
4619 | 373 |
For smalltalk specific formats, |
374 |
see documentation in PrintfScanf >> format_printf. |
|
2241 | 375 |
For copyright information, see goodies/String-printf_scanf.chg" |
2303 | 376 |
|
2241 | 377 |
|aStream| |
378 |
||
3538 | 379 |
aStream := CharacterWriteStream on:(self species uninitializedNew:self size). |
2260 | 380 |
self printf:args on:aStream. |
2241 | 381 |
^ aStream contents |
382 |
||
383 |
" |
|
3796 | 384 |
('%05x %d %f %o' printf:{ 123. 234*5. 1.234. 8r377 } ) |
2303 | 385 |
Transcript showCR:('%05x %d %f %o' printf:{ 123. 234*5. 1.234. 8r377 } ) |
2256 | 386 |
" |
387 |
||
388 |
" |
|
2241 | 389 |
Transcript showCR: 'Some examples:'!! |
390 |
||
391 |
Transcript show:'''%#x %#X %03o%*.*s'' printf: #(16rABCD 16rEF 5 9 5 ''ghijklmn'') = .'. |
|
2303 | 392 |
Transcript show: ('%#x %#X %03o%*.*s' printf: #(16rABCD 16rEF 5 9 5 'ghijklmn')). |
2241 | 393 |
Transcript showCR: '.' |
394 |
||
395 |
Transcript show: '''%- 10.4s%.2e'' printf: (Array with: ''abcdefghijkl'' with: Float pi) = .'. |
|
2303 | 396 |
Transcript show: ('%- 10.4s%.2e' printf: (Array with: 'abcdefghijkl' with: Float pi)). |
2241 | 397 |
Transcript showCR: '.' |
398 |
||
399 |
Transcript show: '''%8.3f'' printf: (Array with: 200 sqrt negated) = .'. |
|
400 |
Transcript show: ('%8.3f' printf: (Array with: 200 sqrt negated)). |
|
401 |
Transcript showCR: '.' |
|
402 |
||
403 |
Transcript show: '''%c'' printf: #(16r41) = .'. |
|
404 |
Transcript show: ('%c' printf: #(16r41)). |
|
405 |
Transcript showCR: '.' |
|
406 |
||
407 |
Transcript show: '''%f%2s%s%s%s'' sscanf: ''237.0 this is a test'' = '. |
|
408 |
Transcript showCR: ('%f%2s%s%s%s' sscanf: '237.0 this is a test') printString. |
|
409 |
||
410 |
Transcript show: '''%d%f%s'' sscanf: ''25 54.32e-01 monday'' = '. |
|
411 |
Transcript showCR: ('%d%f%s' sscanf: '25 54.32e-01 monday') printString. |
|
412 |
||
413 |
Transcript show: '''%f%*f %8[A-F0-9]%c%d 0x%x%f'' sscanf: ''12.45 1048.73 AE40Z527 0x75BCD15 34'' = '. |
|
414 |
Transcript showCR: ('%f%*f %8[A-F0-9]%c%d 0x%x%f' sscanf: '12.45 1048.73 AE40Z527 0x75BCD15 34') printString. |
|
415 |
" |
|
4528 | 416 |
|
417 |
"Modified (comment): / 14-11-2017 / 22:58:01 / cg" |
|
2241 | 418 |
! ! |
419 |
||
420 |
!CharacterArray methodsFor:'printing & storing'! |
|
421 |
||
2260 | 422 |
printf:args on:outStream |
423 |
"Format and print the receiver on <outStream> with <args> |
|
424 |
formatted in C style, as specified in the Unix C-language manual page for printf(3). |
|
4619 | 425 |
For smalltalk specific formats, |
426 |
see documentation in PrintfScanf >> format_printf. |
|
2260 | 427 |
For copyright information, see goodies/String-printf_scanf.chg" |
2303 | 428 |
|
4418 | 429 |
PrintfScanf printf:self on:outStream arguments: args |
430 |
||
431 |
" |
|
432 |
'%e' printf:{ 1234.567 ] on:Transcript |
|
433 |
||
434 |
'%10s%3d\n' printf:{ 'hello' . 12 } on:Transcript |
|
435 |
'%10s%3d\n' printf:{ '1234567890' . 12 } on:Transcript |
|
2260 | 436 |
|
4418 | 437 |
like C's printf, a longer datum may be formatted wider than the formatspec says: |
438 |
||
439 |
'%10s%3d\n' printf:{ '12345678901234' . 12 } on:Transcript |
|
440 |
||
441 |
'%10s%3d\n' printf:{ 'hello' . 12 } on:Transcript |
|
442 |
'%10s%03d\n' printf:{ 'hello' . 12 } on:Transcript |
|
443 |
" |
|
444 |
||
4528 | 445 |
"Modified (comment): / 14-11-2017 / 22:57:58 / cg" |
2260 | 446 |
! ! |
447 |
||
448 |
!CharacterArray methodsFor:'printing & storing'! |
|
449 |
||
2303 | 450 |
printfWith:arg1 |
2295 | 451 |
"Format and print the receiver with <arg1> formatted in C style, |
452 |
as specified in the Unix C-language manual page for printf(3). |
|
4528 | 453 |
Return the resulting string (i.e actually, this is more like an sprintf). |
4619 | 454 |
For smalltalk specific formats, |
455 |
see documentation in PrintfScanf >> format_printf" |
|
2303 | 456 |
|
2256 | 457 |
^ self printf:(Array with:arg1) |
458 |
||
459 |
" |
|
3796 | 460 |
('%05x' printfWith:123) |
2303 | 461 |
Transcript showCR:('%05x' printfWith:123) |
2256 | 462 |
" |
4528 | 463 |
|
464 |
"Modified (comment): / 14-11-2017 / 22:58:10 / cg" |
|
2256 | 465 |
! ! |
466 |
||
467 |
!CharacterArray methodsFor:'printing & storing'! |
|
468 |
||
2303 | 469 |
printfWith:arg1 with:arg2 |
470 |
"Format and print the receiver with <argI> formatted in C style, |
|
2295 | 471 |
as specified in the Unix C-language manual page for printf(3). |
4528 | 472 |
Return the resulting string (i.e actually, this is more like an sprintf). |
4619 | 473 |
For smalltalk specific formats, see documentation in PrintfScanf >> format_printf." |
2303 | 474 |
|
2256 | 475 |
^ self printf:(Array with:arg1 with:arg2) |
476 |
||
477 |
" |
|
2303 | 478 |
Transcript showCR:('%d %05x' printfWith:123 with:234) |
2256 | 479 |
" |
4528 | 480 |
|
481 |
"Modified (comment): / 14-11-2017 / 22:58:16 / cg" |
|
2256 | 482 |
! ! |
483 |
||
484 |
!CharacterArray methodsFor:'printing & storing'! |
|
485 |
||
486 |
printfWith:arg1 with:arg2 with:arg3 |
|
2303 | 487 |
"Format and print the receiver with <argI> formatted in C style, |
2295 | 488 |
as specified in the Unix C-language manual page for printf(3). |
4528 | 489 |
Return the resulting string (i.e actually, this is more like an sprintf). |
4619 | 490 |
For smalltalk specific formats, see documentation in PrintfScanf >> format_printf." |
2303 | 491 |
|
2256 | 492 |
^ self printf:(Array with:arg1 with:arg2 with:arg3) |
493 |
||
494 |
" |
|
2303 | 495 |
Transcript showCR:('%d %05x %08o' printfWith:123 with:234 with:345) |
2256 | 496 |
" |
4528 | 497 |
|
498 |
"Modified (comment): / 14-11-2017 / 22:58:20 / cg" |
|
2256 | 499 |
! ! |
500 |
||
501 |
!CharacterArray methodsFor:'printing & storing'! |
|
502 |
||
503 |
printfWith:arg1 with:arg2 with:arg3 with:arg4 |
|
2303 | 504 |
"Format and print the receiver with <argI> formatted in C style, |
2295 | 505 |
as specified in the Unix C-language manual page for printf(3). |
4528 | 506 |
Return the resulting string (i.e actually, this is more like an sprintf). |
4619 | 507 |
For smalltalk specific formats, see documentation in PrintfScanf >> format_printf." |
2303 | 508 |
|
2256 | 509 |
^ self printf:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
510 |
||
511 |
" |
|
2303 | 512 |
Transcript showCR:('%d %05x %08o %b' printfWith:123 with:234 with:345 with:123) |
2256 | 513 |
" |
4528 | 514 |
|
515 |
"Modified (comment): / 14-11-2017 / 22:58:23 / cg" |
|
516 |
! ! |
|
517 |
||
518 |
!CharacterArray methodsFor:'printing & storing'! |
|
519 |
||
520 |
printfWith:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
521 |
"Format and print the receiver with <argI> formatted in C style, |
|
522 |
as specified in the Unix C-language manual page for printf(3). |
|
523 |
Return the resulting string (i.e actually, this is more like an sprintf). |
|
4619 | 524 |
For smalltalk specific formats, see documentation in PrintfScanf >> format_printf." |
4528 | 525 |
|
526 |
^ self printf:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
527 |
||
528 |
" |
|
529 |
Transcript showCR:('%d %05x %08o %b' printfWith:123 with:234 with:345 with:123) |
|
530 |
" |
|
531 |
||
532 |
"Modified (comment): / 14-11-2017 / 22:58:28 / cg" |
|
2256 | 533 |
! ! |
534 |
||
535 |
!CharacterArray methodsFor:'printing & storing'! |
|
536 |
||
2241 | 537 |
printf_formatArgCount |
538 |
"Return the number of arguments required/produced if the receiver is interpreted |
|
539 |
as a printf/scanf format control string. |
|
4528 | 540 |
For smalltalk specific formats, see documentation in PrintfScanf. |
2241 | 541 |
For copyright information, see goodies/String-printf_scanf.chg" |
2303 | 542 |
|
4418 | 543 |
^ PrintfScanf formatArgCountFor:self. |
2241 | 544 |
|
4418 | 545 |
"Modified: / 19-06-2017 / 16:54:10 / cg" |
4528 | 546 |
"Modified (comment): / 14-11-2017 / 22:58:34 / cg" |
2241 | 547 |
! ! |
548 |
||
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
549 |
!CharacterArray methodsFor:'private'! |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
550 |
|
4418 | 551 |
printf_printArgFrom:formatStream to:outStream withData:argStream |
552 |
<resource: #obsolete> |
|
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
553 |
"Interpret the required number of arguments from <argStream> |
4418 | 554 |
according to the formatting information in <formatStream>. |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
555 |
Place the interpretation on <outStream>. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
556 |
The interpretation is C printf(3) style, as |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
557 |
specified in the Unix C-language manual page for printf(3). |
4418 | 558 |
<formatStream> is assumed to be positioned just past |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
559 |
$%, and a complete control string is assumed available. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
560 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
561 |
Return when the conversion control string is consumed. |
4418 | 562 |
Leave <formatStream> pointing past the last character in the conversion control string. |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
563 |
|
4418 | 564 |
This code assumes that <formatStream> is formatted according to |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
565 |
specification, and error checking is minimal. Unexpected |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
566 |
results will be obtained by illegal control strings, or when |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
567 |
argument types do not match conversion codes, but it probably |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
568 |
won't dump core, like C does in such cases!! |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
569 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
570 |
For copyright information, see goodies/String-printf_scanf.chg" |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
571 |
|
4418 | 572 |
PrintfScanf printArgFrom:formatStream to:outStream arguments:argStream |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
573 |
|
4418 | 574 |
"Modified: / 19-06-2017 / 15:44:28 / cg" |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
575 |
! ! |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
576 |
|
2241 | 577 |
!CharacterArray methodsFor:'printing & storing'! |
578 |
||
2260 | 579 |
printf_printOn:outStream withData:args |
580 |
<resource: #obsolete> |
|
2303 | 581 |
|
2241 | 582 |
"Format and print the receiver on <outStream> with <args> |
583 |
formatted in C style, as specified in the Unix C-language manual page for printf(3). |
|
584 |
||
585 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
586 |
||
2260 | 587 |
self obsoleteMethodWarning:'use printf:on:'. |
588 |
self printf:args on:outStream |
|
2241 | 589 |
! ! |
590 |
||
591 |
!CharacterArray methodsFor:'converting'! |
|
592 |
||
4473 | 593 |
scanf:dataStreamOrString |
2241 | 594 |
"Return a Collection of objects found in the Character Stream |
2303 | 595 |
<dataStream> as interpreted according to the receiver. |
2241 | 596 |
The receiver is assumed to be a conversion control string as |
597 |
specified in the Unix C-language manual page for scanf(3). |
|
598 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 599 |
|
4473 | 600 |
|dataStream| |
2241 | 601 |
|
4473 | 602 |
dataStream := dataStreamOrString readStream. |
603 |
^ PrintfScanf scanf:self fromStream:dataStream |
|
604 |
||
605 |
"/ |results format char| |
|
606 |
"/ |
|
607 |
"/ results := OrderedCollection new. |
|
608 |
"/ format := ReadStream on:self. |
|
609 |
"/ [ format atEnd ] whileFalse:[ |
|
610 |
"/ char := format next. |
|
611 |
"/ (char == Character space or:[ char == Character tab ]) ifTrue:[ |
|
612 |
"/ dataStream skipSeparators. |
|
613 |
"/ format skipSeparators |
|
614 |
"/ ]. |
|
615 |
"/ char == $% ifTrue:[ |
|
616 |
"/ PrintfScanf scanArgFrom:dataStream to:results format:format. |
|
617 |
"/ ] ifFalse:[ |
|
618 |
"/ dataStream peekFor:char |
|
619 |
"/ ] |
|
620 |
"/ ]. |
|
621 |
"/ ^ results |
|
2241 | 622 |
|
623 |
" |
|
2303 | 624 |
'%d %x' scanf:(ReadStream on:'1234 ff00') |
4473 | 625 |
'%d %s' scanf:(ReadStream on:'1234 ff00') |
626 |
'%d %b' scanf:(ReadStream on:'1234 1111') |
|
627 |
'%d %f' scanf:(ReadStream on:'1234 1111') |
|
628 |
'%d %f' scanf:(ReadStream on:'1234 1111.2345') |
|
629 |
'%d %q' scanf:(ReadStream on:'1234 1111.2345') |
|
2241 | 630 |
" |
4473 | 631 |
|
632 |
"Modified: / 14-07-2017 / 11:11:49 / cg" |
|
2241 | 633 |
! ! |
634 |
||
635 |
!CharacterArray methodsFor:'private'! |
|
636 |
||
2303 | 637 |
scanf_scanArgFrom:dataStream to:collection format:format |
4418 | 638 |
<resource: #obsolete> |
2241 | 639 |
"Add to <collection> an object who's representation is found |
640 |
in <dataStream> interpreted according to the conversion |
|
2303 | 641 |
control string in the Stream <format>. |
642 |
<format> is assumed to be positioned just past a $%, and a complete control |
|
2241 | 643 |
string is assumed available. |
644 |
||
645 |
Return when the conversion control string is consumed. Leave |
|
646 |
<format> pointing past the last character in the conversion |
|
647 |
control string, leave <dataStream> pointing past any width |
|
648 |
specified in <format>, or at the first character that doesn't |
|
649 |
make sense for the <format>. |
|
650 |
||
651 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 652 |
|
4473 | 653 |
PrintfScanf scanArgFrom:dataStream to:collection format:format. |
2256 | 654 |
|
655 |
" |
|
2303 | 656 |
'%d %x' sscanf:'1234 ff00' |
657 |
'%d %x %b' sscanf:'1234 ff00 1001' |
|
2256 | 658 |
" |
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
659 |
|
4473 | 660 |
"Modified: / 14-07-2017 / 11:09:35 / cg" |
2241 | 661 |
! ! |
662 |
||
663 |
!CharacterArray methodsFor:'converting'! |
|
664 |
||
2303 | 665 |
sscanf:string |
2241 | 666 |
"Return a Collection of objects found in <string> as |
2303 | 667 |
interpreted according to the receiver. |
2241 | 668 |
The receiver is assumed to be a conversion control string as |
669 |
specified in the Unix C-language manual page for scanf(3). |
|
670 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 671 |
|
2241 | 672 |
^ self scanf:(ReadStream on:string) |
673 |
||
674 |
" |
|
2303 | 675 |
'%d %x' sscanf:'1234 ff00' |
676 |
'%d %x %b' sscanf:'1234 ff00 1001' |
|
2241 | 677 |
" |
678 |
! ! |
|
679 |
||
4714 | 680 |
!CharacterArray methodsFor:'Compatibility-Squeak'! |
681 |
||
682 |
urlDecoded |
|
683 |
"decode %xx form. This is the opposite of #urlEncoded" |
|
684 |
||
685 |
^ HTMLUtilities urlDecoded:self |
|
686 |
||
687 |
" |
|
688 |
'abc%61def' unescapePercents |
|
689 |
'abc%61def' urlDecoded |
|
690 |
||
691 |
(HTMLUtilities urlEncoded:'_-.*Frankfurt(Main) Hbf') unescapePercents |
|
692 |
(HTMLUtilities urlEncoded:'_-.*Frankfurt(Main) Hbf') urlDecoded |
|
693 |
||
694 |
(HTMLUtilities urlEncoded:'-_.*%exept ex+pecco;') unescapePercents |
|
695 |
(HTMLUtilities urlEncoded:'-_.*%exept+ex+pecco;') urlDecoded |
|
696 |
" |
|
697 |
||
698 |
"Created: / 26-08-2018 / 12:41:49 / Claus Gittinger" |
|
699 |
! ! |
|
700 |
||
701 |
!CharacterArray methodsFor:'Compatibility-Squeak'! |
|
702 |
||
703 |
urlEncoded |
|
704 |
"encode into %xx form. This is the opposite of #urlDecoded" |
|
705 |
||
706 |
^ HTMLUtilities urlEncoded:self |
|
707 |
||
708 |
" |
|
709 |
'abcäöüdef' urlEncoded urlDecoded |
|
710 |
'abc%def' urlEncoded urlDecoded |
|
711 |
||
712 |
('_-.*Frankfurt(Main) Hbf' urlEncoded) unescapePercents |
|
713 |
('_-.*Frankfurt(Main) Hbf' urlEncoded) urlDecoded |
|
714 |
||
715 |
('-_.*%exept ex+pecco;' urlEncoded) unescapePercents |
|
716 |
('-_.*%exept+ex+pecco;' urlEncoded) urlDecoded |
|
717 |
" |
|
718 |
||
719 |
"Created: / 26-08-2018 / 13:03:03 / Claus Gittinger" |
|
720 |
! ! |
|
721 |
||
4365
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
722 |
!Collection methodsFor:'converting'! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
723 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
724 |
asHalfFloatArray |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
725 |
"return a new HalfFloatArray with the collection's elements |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
726 |
(which must convert to 16bit half-floats)." |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
727 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
728 |
^ self asArrayOfType:HalfFloatArray |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
729 |
! ! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
730 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
731 |
!Collection methodsFor:'converting'! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
732 |
|
4400 | 733 |
asIdentitySkipList |
734 |
"Answer a IdentitySkipList whose elements are the elements of the |
|
735 |
receiver. The sort order is the default less than or equal." |
|
736 |
||
737 |
^ self as: IdentitySkipList |
|
738 |
! ! |
|
739 |
||
740 |
!Collection methodsFor:'converting'! |
|
741 |
||
4365
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
742 |
asList |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
743 |
"return a new List with the receiver collection's elements" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
744 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
745 |
^ self addAllTo:(List new:self size) |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
746 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
747 |
"Created: 14.2.1997 / 16:25:23 / cg" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
748 |
! ! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
749 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
750 |
!Collection methodsFor:'converting'! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
751 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
752 |
asRunArray |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
753 |
"return a new RunArray with the collection's elements" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
754 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
755 |
^ RunArray from:self. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
756 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
757 |
"/ |runs lastElement occurrences| |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
758 |
"/ |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
759 |
"/ runs := RunArray new. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
760 |
"/ occurrences := 0. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
761 |
"/ self do:[:each | |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
762 |
"/ each == lastElement ifTrue:[ |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
763 |
"/ occurrences := occurrences + 1 |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
764 |
"/ ] ifFalse:[ |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
765 |
"/ runs add:lastElement withOccurrences:occurrences. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
766 |
"/ occurrences := 1. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
767 |
"/ lastElement := each |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
768 |
"/ ]. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
769 |
"/ ]. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
770 |
"/ occurrences ~~ 0 ifTrue:[ |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
771 |
"/ runs add:lastElement withOccurrences:occurrences |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
772 |
"/ ]. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
773 |
"/ ^ runs |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
774 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
775 |
" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
776 |
#(1 2 3 3 3 4 4 4 4 5 6 7) asRunArray |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
777 |
" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
778 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
779 |
"Modified: / 7.4.1998 / 09:50:54 / cg" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
780 |
! ! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
781 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
782 |
!Collection methodsFor:'converting'! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
783 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
784 |
asSharedCollection |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
785 |
"return a shared collection on the receiver. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
786 |
This implements synchronized (i.e. mutually excluded) access to me. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
787 |
Use this for safe access when multiple processes access me concurrently. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
788 |
Notice that this is a general (possibly suboptimal) mechanism, which should |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
789 |
work with all collections. Look for specialized collections (SharedQueue), which are |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
790 |
tuned for this kind of operation." |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
791 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
792 |
^ SharedCollection for:self. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
793 |
! ! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
794 |
|
4400 | 795 |
!Collection methodsFor:'converting'! |
796 |
||
797 |
asSkipList |
|
798 |
"Answer a SkipList whose elements are the elements of the |
|
799 |
receiver. The sort order is the default less than or equal." |
|
800 |
||
801 |
^ self as: SkipList |
|
802 |
! ! |
|
803 |
||
804 |
!Collection methodsFor:'converting'! |
|
805 |
||
806 |
asSkipList: aSortBlock |
|
807 |
"Answer a SkipList whose elements are the elements of the |
|
808 |
receiver. The sort order is defined by the argument, aSortBlock." |
|
809 |
||
810 |
| skipList | |
|
811 |
skipList := SkipList new: self size sortBlock: aSortBlock. |
|
812 |
skipList addAll: self. |
|
813 |
^ skipList |
|
814 |
||
815 |
"Modified (comment): / 18-06-2017 / 22:40:10 / cg" |
|
816 |
! ! |
|
817 |
||
2237 | 818 |
!Float methodsFor:'private'! |
819 |
||
2303 | 820 |
absDecimalPrintOn:aStream digits:digits |
2237 | 821 |
"Place a string representation of the receiver's abs value |
822 |
on <aStream> using <digits> significant digits, using decimal notation. |
|
823 |
This is a helper for printf." |
|
824 |
||
4429 | 825 |
<resource: #obsolete> |
826 |
PrintfScanf absDecimalPrintFloat:self on:aStream digits:digits. |
|
2237 | 827 |
|
4429 | 828 |
"Modified: / 20-06-2017 / 11:49:15 / cg" |
2237 | 829 |
! ! |
830 |
||
831 |
!Float methodsFor:'private'! |
|
832 |
||
2303 | 833 |
absPrintOn:aStream digits:digits |
834 |
"Place a string representation of the receiver's abs value on <aStream> using |
|
2237 | 835 |
<digits> significant digits. |
836 |
This is a helper for printf." |
|
2303 | 837 |
|
4429 | 838 |
<resource: #obsolete> |
4418 | 839 |
PrintfScanf absPrintFloat:self on:aStream digits:digits |
840 |
||
4429 | 841 |
"Modified: / 20-06-2017 / 11:49:11 / cg" |
2237 | 842 |
! ! |
843 |
||
844 |
!Float methodsFor:'private'! |
|
845 |
||
2303 | 846 |
absScientificPrintOn:aStream digits:digits |
2237 | 847 |
"Place a string representation of the receiver's abs value on <aStream> using <digits> significant |
848 |
digits, using scientific notation. |
|
849 |
This is a helper for printf." |
|
2303 | 850 |
|
4429 | 851 |
<resource: #obsolete> |
4418 | 852 |
PrintfScanf absScientificPrintFloat:self on:aStream digits:digits. |
2237 | 853 |
|
4418 | 854 |
"Modified: / 19-06-2017 / 14:59:56 / cg" |
4429 | 855 |
"Modified (format): / 20-06-2017 / 11:49:07 / cg" |
2237 | 856 |
! ! |
857 |
||
4381 | 858 |
!Float methodsFor:'coercing & converting'! |
859 |
||
860 |
asQDouble |
|
861 |
"return a QDouble with my value" |
|
862 |
||
863 |
^ QDouble fromFloat:self |
|
864 |
||
865 |
" |
|
866 |
1.0 asQDouble |
|
867 |
" |
|
868 |
||
869 |
"Created: / 13-06-2017 / 16:48:57 / cg" |
|
870 |
! ! |
|
871 |
||
4383 | 872 |
!Integer methodsFor:'coercing & converting'! |
873 |
||
874 |
asQDouble |
|
875 |
"return a QDouble with same value as myself." |
|
876 |
||
877 |
^ QDouble fromInteger:self |
|
878 |
||
879 |
" |
|
880 |
1234567890 asQDouble |
|
881 |
1234567890 asQDouble asInteger |
|
882 |
12345678901234567890 asQDouble |
|
883 |
12345678901234567890 asQDouble asInteger |
|
884 |
" |
|
885 |
||
886 |
"Created: / 12-06-2017 / 18:41:07 / cg" |
|
887 |
"Modified (comment): / 12-06-2017 / 20:55:24 / cg" |
|
888 |
! ! |
|
889 |
||
1759 | 890 |
!Object methodsFor:'dependents-interests'! |
891 |
||
892 |
addInterest:anInterest |
|
893 |
"install an interest forwarder. |
|
894 |
Here, we use the nonWeakDependencies." |
|
895 |
||
896 |
self addNonWeakDependent:anInterest |
|
897 |
||
898 |
"Created: 14.10.1996 / 22:27:34 / stefan" |
|
899 |
! ! |
|
900 |
||
3896 | 901 |
!Object methodsFor:'converting'! |
902 |
||
903 |
asDoubleLink |
|
904 |
"return a valueDoubleLink for the receiver. |
|
905 |
Used to make sure the receiver can be added to a double linked list" |
|
906 |
||
907 |
^ ValueDoubleLink value:self |
|
908 |
! ! |
|
909 |
||
1759 | 910 |
!Object methodsFor:'dependents-interests'! |
911 |
||
912 |
expressInterestIn:aspect for:anObject sendBack:aSelector |
|
913 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
914 |
changes aspect." |
|
915 |
||
916 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
917 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
918 |
||
2303 | 919 |
self addInterest:(InterestConverter |
920 |
destination:anObject |
|
921 |
selector:aSelector |
|
922 |
aspect:aspect) |
|
1759 | 923 |
|
924 |
" |
|
925 |
|p b| |
|
926 |
||
927 |
b := [Transcript showCR:' -> the point changed']. |
|
928 |
||
929 |
p := Point new. |
|
930 |
Transcript showCR:'interest in #foo:'. |
|
931 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
932 |
p x:1. |
|
933 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
934 |
p changed:#bar. |
|
935 |
Transcript cr. |
|
936 |
||
937 |
Delay waitForSeconds:1. |
|
938 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
939 |
p changed:#foo. |
|
940 |
Transcript cr. |
|
941 |
||
942 |
Delay waitForSeconds:1. |
|
943 |
Transcript showCR:'no more interest in #foo:'. |
|
944 |
p retractInterestIn:#foo for:b. |
|
945 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
946 |
p changed:#foo. |
|
947 |
Transcript cr. |
|
948 |
||
949 |
Delay waitForSeconds:1. |
|
950 |
Transcript showCR:'interest in #bar now:'. |
|
951 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
952 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
953 |
p changed:#foo. |
|
954 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
955 |
p changed:#bar. |
|
956 |
Transcript cr. |
|
957 |
||
958 |
Delay waitForSeconds:1. |
|
959 |
Transcript showCR:'interest in #foo now:'. |
|
960 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
961 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
962 |
p changed:#foo. |
|
963 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
964 |
p changed:#bar. |
|
965 |
Transcript cr. |
|
966 |
||
967 |
Delay waitForSeconds:1. |
|
968 |
Transcript showCR:'no more interests:'. |
|
969 |
p retractInterestsFor:b. |
|
970 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
971 |
p changed:#foo. |
|
972 |
Transcript showCR:'now changing #bar... (expect no notification)'. |
|
973 |
p changed:#bar. |
|
974 |
Transcript cr. |
|
975 |
||
976 |
p release. |
|
977 |
" |
|
1668 | 978 |
|
1759 | 979 |
"Created: 19.4.1996 / 10:26:22 / cg" |
980 |
"Modified: 19.4.1996 / 12:34:08 / cg" |
|
981 |
"Modified: 14.10.1996 / 22:28:20 / stefan" |
|
982 |
! ! |
|
983 |
||
984 |
!Object methodsFor:'dependents-interests'! |
|
985 |
||
986 |
interests |
|
987 |
"return a Collection of interests - empty if there is none. |
|
988 |
Here, we use the nonWeakDependents for interests." |
|
989 |
||
990 |
^ self nonWeakDependents |
|
991 |
||
992 |
"Created: / 14.10.1996 / 22:20:51 / stefan" |
|
993 |
"Modified: / 30.1.1998 / 14:07:35 / cg" |
|
994 |
! ! |
|
995 |
||
996 |
!Object methodsFor:'dependents-interests'! |
|
997 |
||
998 |
interestsFor:someOne |
|
999 |
"return a collection of interests of someOne - empty if there is none." |
|
1000 |
||
1001 |
|coll deps| |
|
1002 |
||
1003 |
deps := self interests. |
|
1004 |
deps size == 0 ifTrue:[^ #()]. |
|
1005 |
||
1006 |
coll := IdentitySet new. |
|
1007 |
||
1008 |
deps do:[:dep | |
|
2303 | 1009 |
(dep isInterestConverter) ifTrue:[ |
1010 |
dep destination == someOne ifTrue:[ |
|
1011 |
coll add:dep. |
|
1012 |
] |
|
1013 |
] |
|
1759 | 1014 |
]. |
1015 |
^ coll |
|
1016 |
||
1017 |
"Created: / 30.1.1998 / 14:02:26 / cg" |
|
1018 |
"Modified: / 30.1.1998 / 14:08:24 / cg" |
|
1019 |
! ! |
|
1668 | 1020 |
|
1759 | 1021 |
!Object methodsFor:'dependents-interests'! |
1022 |
||
1023 |
onChangeEvaluate:aBlock |
|
1024 |
"arrange for aBlock to be evaluated whenever the receiver changes." |
|
1025 |
||
2149
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
1026 |
|na selector| |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
1027 |
|
3559
fa3443d808a1
Changed Object>>#onChangeEvaluate: (send #argumentCount instead of #numArgs)
Stefan Vogel <sv@exept.de>
parents:
3538
diff
changeset
|
1028 |
na := aBlock argumentCount. |
2149
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
1029 |
na == 0 ifTrue:[ |
3559
fa3443d808a1
Changed Object>>#onChangeEvaluate: (send #argumentCount instead of #numArgs)
Stefan Vogel <sv@exept.de>
parents:
3538
diff
changeset
|
1030 |
selector := #value |
2149
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
1031 |
] ifFalse:[ |
3559
fa3443d808a1
Changed Object>>#onChangeEvaluate: (send #argumentCount instead of #numArgs)
Stefan Vogel <sv@exept.de>
parents:
3538
diff
changeset
|
1032 |
selector := #( #'value:' #'value:value:' #'value:value:value:') at:na |
2149
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
1033 |
]. |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
1034 |
^ self onChangeSend:selector to:aBlock |
1759 | 1035 |
|
1036 |
" |
|
1037 |
|p b| |
|
1038 |
||
1039 |
b := [Transcript showCR:' -> the point changed']. |
|
1040 |
||
1041 |
p := Point new. |
|
1042 |
Transcript showCR:'interest in #foo:'. |
|
1043 |
p onChangeEvaluate:b. |
|
1044 |
p x:1. |
|
1045 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
1046 |
p changed:#bar. |
|
1047 |
||
1048 |
p retractInterests. |
|
1049 |
p changed:#bar. |
|
1050 |
" |
|
1051 |
! ! |
|
1052 |
||
1053 |
!Object methodsFor:'dependents-interests'! |
|
1054 |
||
1055 |
onChangeSend:aSelector to:anObject |
|
1056 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
4030 | 1057 |
changes. |
1058 |
Use retractInterestsFor: in case you are no longer interested" |
|
1759 | 1059 |
|
1060 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
1061 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1062 |
||
4773 | 1063 |
(self interests contains:[:anInterest | |
1064 |
anInterest isInterestConverter |
|
1065 |
and:[anInterest destination == anObject |
|
1066 |
and:[anInterest selector == aSelector]] |
|
1067 |
] |
|
1068 |
) ifFalse:[ |
|
1069 |
self addInterest:(InterestConverter |
|
1070 |
destination:anObject |
|
1071 |
selector:aSelector) |
|
1072 |
]. |
|
1759 | 1073 |
|
1668 | 1074 |
|
1075 |
" |
|
1759 | 1076 |
|p b| |
1077 |
||
1078 |
b := [Transcript showCR:'the point changed']. |
|
1079 |
||
1080 |
p := Point new. |
|
1081 |
p onChangeSend:#value to:b. |
|
1082 |
p x:1. |
|
1083 |
Transcript showCR:'now changing'. |
|
1084 |
p changed. |
|
1085 |
Transcript cr. |
|
1086 |
||
1087 |
Delay waitForSeconds:1. |
|
1088 |
Transcript showCR:'now changing'. |
|
1089 |
p changed. |
|
1090 |
Transcript cr. |
|
1091 |
||
1092 |
Delay waitForSeconds:1. |
|
1093 |
Transcript showCR:'no more interest'. |
|
1094 |
p retractInterestsFor:b. |
|
1095 |
Transcript showCR:'now changing again'. |
|
1096 |
p changed. |
|
1097 |
Transcript cr. |
|
1098 |
||
1099 |
Delay waitForSeconds:1. |
|
1100 |
Transcript showCR:'interest again'. |
|
1101 |
p onChangeSend:#value to:b. |
|
1102 |
Transcript showCR:'now changing again'. |
|
1103 |
p changed. |
|
1104 |
Transcript cr. |
|
1105 |
" |
|
1106 |
||
4773 | 1107 |
"Created: / 19-04-1996 / 10:26:38 / cg" |
1108 |
"Modified: / 19-04-1996 / 12:34:26 / cg" |
|
1109 |
"Modified: / 14-10-1996 / 22:28:27 / stefan" |
|
1110 |
"Modified: / 30-11-2018 / 18:01:47 / Stefan Vogel" |
|
1759 | 1111 |
! ! |
1112 |
||
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1113 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1114 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1115 |
removeActionsForEvent:eventSymbol |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1116 |
"remove ST/V-style event triggers." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1117 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1118 |
self retractInterestsIn:eventSymbol |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1119 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1120 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1121 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1122 |
|
2903 | 1123 |
removeActionsWithReceiver:aReceiver |
1124 |
"remove ST/V-style event triggers." |
|
1125 |
||
1126 |
self retractInterestsFor:aReceiver |
|
1127 |
! ! |
|
1128 |
||
1129 |
!Object methodsFor:'dependents-st/v event simulation'! |
|
1130 |
||
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1131 |
removeAllActionsWithReceiver:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1132 |
"remove ST/V-style event triggers." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1133 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1134 |
self retractInterestsFor:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1135 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1136 |
|
1759 | 1137 |
!Object methodsFor:'dependents-interests'! |
1138 |
||
1139 |
removeInterest:anInterest |
|
1140 |
"remove an interest forwarder. |
|
1141 |
Here, we use the nonWeakDependencies." |
|
1142 |
||
1143 |
self removeNonWeakDependent:anInterest |
|
1144 |
||
1145 |
"Created: 14.10.1996 / 22:21:59 / stefan" |
|
1146 |
! ! |
|
1147 |
||
1148 |
!Object methodsFor:'dependents-interests'! |
|
1149 |
||
1150 |
retractInterestIn:aspect for:someOne |
|
1151 |
"remove the interest of someOne in the receiver changing aspect |
|
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1152 |
(as installed with #expressInterestIn:for:sendBack:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1153 |
Answer the retracted interests." |
1759 | 1154 |
|
1155 |
"/ for now, remove the interestConverter. |
|
1156 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1157 |
||
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1158 |
^ self retractInterestsForWhich:[:i | |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1159 |
(i aspect == aspect) and:[i destination == someOne] |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1160 |
] |
1759 | 1161 |
|
1668 | 1162 |
" |
1759 | 1163 |
|p b| |
1164 |
||
1165 |
b := [Transcript showCR:'the point changed']. |
|
1166 |
||
1167 |
p := Point new. |
|
1168 |
Transcript showCR:'interest in #foo'. |
|
1169 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
1170 |
p x:1. |
|
1171 |
Transcript showCR:'now changing #bar'. |
|
1172 |
p changed:#bar. |
|
1173 |
Transcript cr. |
|
1174 |
||
1175 |
Delay waitForSeconds:1. |
|
1176 |
Transcript showCR:'now changing #foo'. |
|
1177 |
p changed:#foo. |
|
1178 |
Transcript cr. |
|
1179 |
||
1180 |
Delay waitForSeconds:1. |
|
1181 |
Transcript showCR:'no more interest in #foo'. |
|
1182 |
p retractInterestIn:#foo for:b. |
|
1183 |
Transcript showCR:'now changing #foo'. |
|
1184 |
p changed:#foo. |
|
1185 |
Transcript cr. |
|
1186 |
||
1187 |
Delay waitForSeconds:1. |
|
1188 |
Transcript showCR:'interest in #bar now'. |
|
1189 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
1190 |
Transcript showCR:'now changing #foo'. |
|
1191 |
p changed:#foo. |
|
1192 |
Transcript showCR:'now changing #bar'. |
|
1193 |
p changed:#bar. |
|
1194 |
Transcript cr. |
|
1195 |
||
1196 |
Delay waitForSeconds:1. |
|
1197 |
Transcript showCR:'interest in #foo now'. |
|
1198 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
1199 |
Transcript showCR:'now changing #foo'. |
|
1200 |
p changed:#foo. |
|
1201 |
Transcript showCR:'now changing #bar'. |
|
1202 |
p changed:#bar. |
|
1203 |
Transcript cr. |
|
1204 |
||
1205 |
Delay waitForSeconds:1. |
|
1206 |
Transcript showCR:'no more interests'. |
|
1207 |
p retractInterestsFor:b. |
|
1208 |
Transcript showCR:'now changing #foo'. |
|
1209 |
p changed:#foo. |
|
1210 |
Transcript showCR:'now changing #bar'. |
|
1211 |
p changed:#bar. |
|
1212 |
Transcript cr. |
|
1213 |
" |
|
1214 |
||
1215 |
"Created: / 19.4.1996 / 10:27:11 / cg" |
|
1216 |
"Modified: / 14.10.1996 / 22:21:19 / stefan" |
|
1217 |
"Modified: / 30.1.1998 / 14:05:34 / cg" |
|
1218 |
! ! |
|
1219 |
||
1220 |
!Object methodsFor:'dependents-interests'! |
|
1221 |
||
1222 |
retractInterests |
|
1223 |
"remove all interests in the receiver changing aspect |
|
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1224 |
(as installed with #expressInterestIn:for:sendBack:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1225 |
Answer the retraced interests." |
1759 | 1226 |
|
1227 |
"/ for now, remove the interestConverter. |
|
1228 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1229 |
||
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1230 |
^ self retractInterestsForWhich:[:i | true ] |
1759 | 1231 |
! ! |
1232 |
||
1233 |
!Object methodsFor:'dependents-interests'! |
|
1234 |
||
1235 |
retractInterestsFor:someOne |
|
2303 | 1236 |
"remove the interest of someOne in the receiver |
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1237 |
(as installed with #onChangeSend:to:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1238 |
Answer the retracted interests." |
1759 | 1239 |
|
1240 |
"/ for now, remove the interestConverter. |
|
1241 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1242 |
||
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1243 |
^ self retractInterestsForWhich:[:i | i destination == someOne ] |
1759 | 1244 |
|
1245 |
" |
|
1246 |
|p b| |
|
1247 |
||
1248 |
b := [Transcript showCR:'the point changed']. |
|
1249 |
||
1250 |
p := Point new. |
|
1251 |
p onChangeSend:#value to:b. |
|
1252 |
p x:1. |
|
1253 |
Transcript showCR:'now changing'. |
|
1254 |
p changed. |
|
1255 |
Transcript cr. |
|
1256 |
||
1257 |
Delay waitForSeconds:1. |
|
1258 |
Transcript showCR:'now changing'. |
|
1259 |
p changed. |
|
1260 |
Transcript cr. |
|
1261 |
||
1262 |
Delay waitForSeconds:1. |
|
1263 |
Transcript showCR:'no more interest'. |
|
1264 |
p retractInterestsFor:b. |
|
1265 |
Transcript showCR:'now changing again'. |
|
1266 |
p changed. |
|
1267 |
Transcript cr. |
|
1268 |
||
1269 |
Delay waitForSeconds:1. |
|
1270 |
Transcript showCR:'interest again'. |
|
1271 |
p onChangeSend:#value to:b. |
|
1272 |
Transcript showCR:'now changing again'. |
|
1273 |
p changed. |
|
1274 |
Transcript cr. |
|
1275 |
" |
|
1276 |
||
1277 |
"Created: / 19.4.1996 / 10:23:46 / cg" |
|
1278 |
"Modified: / 14.10.1996 / 22:21:25 / stefan" |
|
1279 |
"Modified: / 30.1.1998 / 14:04:52 / cg" |
|
1280 |
! ! |
|
1281 |
||
1282 |
!Object methodsFor:'dependents-interests'! |
|
1283 |
||
1284 |
retractInterestsForWhich:aBlock |
|
1285 |
"remove all interests in the receiver changing aspect |
|
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1286 |
(as installed with #expressInterestIn:for:sendBack:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1287 |
Answer the retracted interests." |
1759 | 1288 |
|
1289 |
"/ for now, remove the interestConverter. |
|
1290 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1291 |
||
1292 |
|deps coll| |
|
1293 |
||
1294 |
deps := self interests. |
|
1295 |
deps size ~~ 0 ifTrue:[ |
|
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1296 |
"/ cannot removeDependent within the loop - the interests collection rehashes |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1297 |
coll := IdentitySet new. |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1298 |
deps do:[:dep | |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1299 |
dep isInterestConverter ifTrue:[ |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1300 |
(aBlock value:dep) ifTrue:[coll add:dep]. |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1301 |
] |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1302 |
]. |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1303 |
coll do:[:dep | |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1304 |
self removeInterest:dep. |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1305 |
]. |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1306 |
^ coll. |
1759 | 1307 |
]. |
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1308 |
^ #() |
1759 | 1309 |
! ! |
1310 |
||
1311 |
!Object methodsFor:'dependents-interests'! |
|
1312 |
||
1313 |
retractInterestsIn:aspect |
|
1314 |
"remove all interests in the receiver changing aspect |
|
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1315 |
(as installed with #expressInterestIn:for:sendBack:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1316 |
Answer the retracted interests." |
1759 | 1317 |
|
1318 |
"/ for now, remove the interestConverter. |
|
1319 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1320 |
||
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1321 |
^ self retractInterestsForWhich:[:i | i aspect == aspect ] |
1668 | 1322 |
! ! |
1323 |
||
2901 | 1324 |
!Object methodsFor:'Compatibility-Dolphin'! |
1325 |
||
1326 |
trigger:anAspect |
|
1327 |
self changed:anAspect |
|
1328 |
! ! |
|
1329 |
||
1330 |
!Object methodsFor:'Compatibility-Dolphin'! |
|
1331 |
||
1332 |
trigger:anAspect with:anArgument |
|
1333 |
self changed:anAspect with:anArgument |
|
1334 |
! ! |
|
1335 |
||
1336 |
!Object methodsFor:'dependents-st/v event simulation'! |
|
1337 |
||
1338 |
triggerEvent:aSymbol |
|
1339 |
self changed:aSymbol |
|
1340 |
! ! |
|
1341 |
||
1668 | 1342 |
!Object methodsFor:'dependents-st/v event simulation'! |
1343 |
||
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1344 |
triggerEvent:eventSymbol with:aParameter |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1345 |
"perform ST/V-style event triggering." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1346 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1347 |
self changed:eventSymbol with:(Array with:aParameter). |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1348 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1349 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1350 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1351 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1352 |
triggerEvent:eventSymbol withArguments:parameters |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1353 |
"perform ST/V-style event triggering." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1354 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1355 |
self changed:eventSymbol with:parameters. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1356 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1357 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1358 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1359 |
|
1668 | 1360 |
when:eventSymbol send:selector to:anObject |
1361 |
"install an ST/V-style interest forwarder. |
|
1362 |
Here, we use the nonWeakDependencies." |
|
1363 |
||
1364 |
self addInterest:(InterestConverterWithParameters |
|
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1365 |
destination:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1366 |
selector:selector |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1367 |
aspect:eventSymbol). |
1668 | 1368 |
|
1369 |
" |
|
1370 |
|p b| |
|
1371 |
||
1372 |
b := [Transcript showCR:'the point changed']. |
|
1373 |
||
1374 |
p := Point new. |
|
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1375 |
p when:#foo:bar: send:#value:value: to:[:a :b | Transcript show:'foo: '; show:a; show:' bar: '; showCR:b]. |
1668 | 1376 |
Transcript showCR:'now changing'. |
1377 |
p triggerEvent:#foo:bar: withArguments:#('fooArg' 'barArg'). |
|
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1378 |
p removeActionsForEvent:#foo:bar:. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1379 |
" |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1380 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1381 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1382 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1383 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1384 |
when:eventSymbol send:selector to:anObject with:aParameter |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1385 |
"install an ST/V-style interest forwarder. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1386 |
Here, we use the nonWeakDependencies." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1387 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1388 |
self addInterest:((InterestConverterWithParameters |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1389 |
destination:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1390 |
selector:selector |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1391 |
aspect:eventSymbol) |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1392 |
defaultParameters:(Array with:aParameter)). |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1393 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1394 |
" |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1395 |
|p b| |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1396 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1397 |
b := [Transcript showCR:'the point changed']. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1398 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1399 |
p := Point new. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1400 |
p |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1401 |
when:#foo: |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1402 |
send:#value: |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1403 |
to:[:a | Transcript show:'foo: '; showCR:a] |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1404 |
with:123. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1405 |
Transcript showCR:'now changing'. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1406 |
p triggerEvent:#foo:. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1407 |
p triggerEvent:#foo: with:987. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1408 |
p removeActionsForEvent:#foo:. |
1668 | 1409 |
" |
1410 |
! ! |
|
1411 |
||
2901 | 1412 |
!Object methodsFor:'Compatibility-Dolphin'! |
1413 |
||
1414 |
when:anAspect sendTo:anObject |
|
1415 |
self expressInterestIn:anAspect for:anObject sendBack:anAspect |
|
1416 |
! ! |
|
1417 |
||
2364 | 1418 |
!Stream methodsFor:'stacked computing streams'! |
1419 |
||
1420 |
collecting:aBlock |
|
1421 |
"return a stacked computing stream, which reads elements from the receiver, |
|
1422 |
applies aBlock to each read element, and provides the results as elements to its reader." |
|
1423 |
||
1424 |
^ CollectingReadStream on:self collecting:aBlock |
|
3094 | 1425 |
|
1426 |
" |
|
1427 |
|s s2| |
|
1428 |
||
1429 |
s := 'hello world' readStream. |
|
1430 |
s2 := s collecting:[:ch | ch asUppercase]. |
|
1431 |
s2 upToEnd. |
|
1432 |
" |
|
2364 | 1433 |
! ! |
1434 |
||
4620 | 1435 |
!Stream methodsFor:'writing'! |
1436 |
||
1437 |
printf:format |
|
1438 |
"C-style printing into a stream. |
|
1439 |
For smalltalk specific formats, |
|
1440 |
see documentation in PrintfScanf >> format_printf" |
|
1441 |
||
1442 |
format printf:#() on:self. |
|
1443 |
||
1444 |
" |
|
1445 |
Transcript printf:'Hello World\n' |
|
1446 |
" |
|
1447 |
! ! |
|
1448 |
||
1449 |
!Stream methodsFor:'writing'! |
|
1450 |
||
1451 |
printf:format arguments:arguments |
|
1452 |
"C-style printing into a stream. |
|
1453 |
Same as printf:withAll:, for protocol completeness. |
|
1454 |
For smalltalk specific formats, |
|
1455 |
see documentation in PrintfScanf >> format_printf" |
|
1456 |
||
1457 |
format printf:arguments on:self. |
|
1458 |
||
1459 |
" |
|
1460 |
Transcript printf:'%05x %d %f %o\n' withAll:{ 123. 234*5. 1.234. 8r377 } |
|
1461 |
Transcript printf:'%03d %03d %03d\n' withAll:{ 1. 2. 3 } |
|
1462 |
" |
|
1463 |
||
1464 |
"Created: / 23-02-2017 / 16:43:39 / cg" |
|
1465 |
! ! |
|
1466 |
||
1467 |
!Stream methodsFor:'writing'! |
|
1468 |
||
1469 |
printf:format with:argument |
|
1470 |
"C-style printing into a stream. |
|
1471 |
For smalltalk specific formats, |
|
1472 |
see documentation in PrintfScanf >> format_printf" |
|
1473 |
||
1474 |
format printf:{argument} on:self. |
|
1475 |
||
1476 |
" |
|
1477 |
Transcript printf:'%05x\n' with:12345 |
|
1478 |
" |
|
1479 |
! ! |
|
1480 |
||
1481 |
!Stream methodsFor:'writing'! |
|
1482 |
||
1483 |
printf:format with:argument1 with:argument2 |
|
1484 |
"C-style printing into a stream. |
|
1485 |
For smalltalk specific formats, |
|
1486 |
see documentation in PrintfScanf >> format_printf" |
|
1487 |
||
1488 |
format printf:{argument1 . argument2} on:self. |
|
1489 |
||
1490 |
" |
|
1491 |
Transcript printf:'%05x %3s\n' with:12345 with:'abc' |
|
1492 |
" |
|
1493 |
! ! |
|
1494 |
||
1495 |
!Stream methodsFor:'writing'! |
|
1496 |
||
1497 |
printf:format with:argument1 with:argument2 with:argument3 |
|
1498 |
"C-style printing into a stream. |
|
1499 |
For smalltalk specific formats, |
|
1500 |
see documentation in PrintfScanf >> format_printf" |
|
1501 |
||
1502 |
format printf:{argument1 . argument2 . argument3} on:self. |
|
1503 |
||
1504 |
" |
|
1505 |
Transcript printf:'%05x %3s %09s\n' with:12345 with:'abc' with:'abc' |
|
1506 |
Transcript printf:'%05x %3s %9s\n' with:12345 with:'abc' with:'abc' |
|
1507 |
" |
|
1508 |
! ! |
|
1509 |
||
1510 |
!Stream methodsFor:'writing'! |
|
1511 |
||
1512 |
printf:format with:argument1 with:argument2 with:argument3 with:argument4 |
|
1513 |
"C-style printing into a stream. |
|
1514 |
For smalltalk specific formats, |
|
1515 |
see documentation in PrintfScanf >> format_printf" |
|
1516 |
||
1517 |
format printf:{argument1 . argument2 . argument3 . argument4} on:self. |
|
1518 |
||
1519 |
" |
|
1520 |
Transcript printf:'%02x %02x %02x %02x\n' with:1 with:2 with:3 with:4 |
|
1521 |
Transcript printf:'%2x %2x %2x %2x\n' with:1 with:2 with:3 with:4 |
|
1522 |
Transcript printf:'%-2x %-2x %-2x %-2x\n' with:1 with:2 with:3 with:4 |
|
1523 |
" |
|
1524 |
! ! |
|
1525 |
||
1526 |
!Stream methodsFor:'writing'! |
|
1527 |
||
1528 |
printf:format with:argument1 with:argument2 with:argument3 with:argument4 with:argument5 |
|
1529 |
"C-style printing into a stream. |
|
1530 |
For smalltalk specific formats, |
|
1531 |
see documentation in PrintfScanf >> format_printf" |
|
1532 |
||
1533 |
format printf:{argument1 . argument2 . argument3 . argument4 . argument5} on:self. |
|
1534 |
||
1535 |
" |
|
1536 |
Transcript printf:'%02x %02x %02x %02x\n' with:1 with:2 with:3 with:4 |
|
1537 |
Transcript printf:'%2x %2x %2x %2x\n' with:1 with:2 with:3 with:4 |
|
1538 |
Transcript printf:'%-2x %-2x %-2x %-2x\n' with:1 with:2 with:3 with:4 |
|
1539 |
" |
|
1540 |
! ! |
|
1541 |
||
1542 |
!Stream methodsFor:'writing'! |
|
1543 |
||
1544 |
printf:format withAll:arguments |
|
1545 |
"C-style printing into a stream. |
|
1546 |
For smalltalk specific formats, |
|
1547 |
see documentation in PrintfScanf >> format_printf" |
|
1548 |
||
1549 |
format printf:arguments on:self. |
|
1550 |
||
1551 |
" |
|
1552 |
Transcript printf:'%05x %d %f %o\n' withAll:{ 123. 234*5. 1.234. 8r377 } |
|
1553 |
Transcript printf:'%03d %03d %03d\n' withAll:{ 1. 2. 3 } |
|
1554 |
" |
|
1555 |
! ! |
|
1556 |
||
2364 | 1557 |
!Stream methodsFor:'stacked computing streams'! |
1558 |
||
1559 |
selecting:aBlock |
|
1560 |
"return a stacked computing stream, which reads elements from the receiver, |
|
1561 |
but only provides elements for which aBlock returns true to its reader." |
|
1562 |
||
1563 |
^ SelectingReadStream on:self selecting:aBlock |
|
3094 | 1564 |
|
1565 |
" |
|
1566 |
|s s2| |
|
1567 |
||
1568 |
s := 'hello world' readStream. |
|
1569 |
s2 := s selecting:[:ch | ch isVowel]. |
|
1570 |
s2 upToEnd. |
|
1571 |
" |
|
2364 | 1572 |
! ! |
1573 |
||
2303 | 1574 |
!stx_libbasic2 class methodsFor:'documentation'! |
1575 |
||
1576 |
extensionsVersion_CVS |
|
3715 | 1577 |
^ '$Header$' |
3005 | 1578 |
! ! |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
1579 |