author | Claus Gittinger <cg@exept.de> |
Sat, 02 May 2020 21:40:13 +0200 | |
changeset 5476 | 7355a4b11cb6 |
parent 5455 | 20dbad6d9935 |
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 |
||
5293
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
21 |
!ArithmeticValue methodsFor:'converting'! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
22 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
23 |
asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
24 |
"return a quadFloat with same value" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
25 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
26 |
"WARNING: could loose precision here, if not redefined in concrete classes which |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
27 |
have more than float precision (i.e. LargeIntegers and Fractions)" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
28 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
29 |
^ self asFloat asQuadFloat "/ subclassResponsibility |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
30 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
31 |
"Created: / 07-06-2019 / 02:28:54 / Claus Gittinger" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
32 |
! ! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
33 |
|
4379
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
34 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
35 |
|
5325 | 36 |
differenceFromIEEEFloat:anIEEEFloat |
37 |
"anIEEEFloat does not know how to subtract the receiver - |
|
38 |
retry the operation by coercing to higher generality" |
|
39 |
||
40 |
^ anIEEEFloat retry:#- coercing:self |
|
41 |
||
42 |
||
43 |
! ! |
|
44 |
||
45 |
!ArithmeticValue methodsFor:'double dispatching'! |
|
46 |
||
4379
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
47 |
differenceFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
48 |
"aQDouble does not know how to subtract the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
49 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
50 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
51 |
^ aQDouble retry:#- coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
52 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
53 |
"Created: / 13-06-2017 / 08:55:38 / cg" |
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 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
56 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
57 |
|
5325 | 58 |
equalFromIEEEFloat:anIEEEFloat |
59 |
"anIEEEFloat does not know how to compare against by the receiver - |
|
60 |
retry the operation by coercing to higher generality" |
|
61 |
||
62 |
^ anIEEEFloat retry:#= coercing:self |
|
63 |
! ! |
|
64 |
||
65 |
!ArithmeticValue methodsFor:'double dispatching'! |
|
66 |
||
4379
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
67 |
equalFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
68 |
"aQDouble does not know how to compare to the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
69 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
70 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
71 |
^ aQDouble retry:#= coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
72 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
73 |
"Created: / 13-06-2017 / 08:55:30 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
74 |
! ! |
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 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
77 |
|
5325 | 78 |
lessFromIEEEFloat:anIEEEFloat |
79 |
"anIEEEFloat does not know how to compare against by the receiver - |
|
80 |
retry the operation by coercing to higher generality" |
|
81 |
||
82 |
^ anIEEEFloat retry:#< coercing:self |
|
83 |
! ! |
|
84 |
||
85 |
!ArithmeticValue methodsFor:'double dispatching'! |
|
86 |
||
4379
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
87 |
lessFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
88 |
"aQDouble does not know how to compare to the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
89 |
Return true if aQDouble < self. |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
90 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
91 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
92 |
^ aQDouble retry:#< coercing:self |
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 |
"Created: / 13-06-2017 / 08:55:20 / cg" |
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 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
97 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
98 |
|
5325 | 99 |
productFromIEEEFloat:anIEEEFloat |
100 |
"anIEEEFloat does not know how to multiply the receiver - |
|
101 |
retry the operation by coercing to higher generality" |
|
102 |
||
103 |
^ anIEEEFloat retry:#* coercing:self |
|
104 |
! ! |
|
105 |
||
106 |
!ArithmeticValue methodsFor:'double dispatching'! |
|
107 |
||
4379
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
108 |
productFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
109 |
"aQDouble does not know how to multiply the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
110 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
111 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
112 |
^ aQDouble retry:#* coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
113 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
114 |
"Created: / 13-06-2017 / 08:55:07 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
115 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
116 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
117 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
118 |
|
5325 | 119 |
quotientFromIEEEFloat:anIEEEFloat |
120 |
"anIEEEFloat does not know how to divide by the receiver - |
|
121 |
retry the operation by coercing to higher generality" |
|
122 |
||
123 |
^ anIEEEFloat retry:#/ coercing:self |
|
124 |
! ! |
|
125 |
||
126 |
!ArithmeticValue methodsFor:'double dispatching'! |
|
127 |
||
4379
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
128 |
quotientFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
129 |
"aQDouble does not know how to divide by the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
130 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
131 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
132 |
^ aQDouble retry:#/ coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
133 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
134 |
"Created: / 13-06-2017 / 08:54:55 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
135 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
136 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
137 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
138 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
139 |
remainderFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
140 |
"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
|
141 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
142 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
143 |
^ aQDouble retry:#rem: coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
144 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
145 |
"Created: / 13-06-2017 / 08:54:47 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
146 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
147 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
148 |
!ArithmeticValue methodsFor:'double dispatching'! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
149 |
|
5325 | 150 |
sumFromIEEEFloat:anIEEEFloat |
151 |
"anIEEEFloat does not know how to add the receiver - |
|
152 |
retry the operation by coercing to higher generality" |
|
153 |
||
154 |
^ anIEEEFloat retry:#+ coercing:self |
|
155 |
! ! |
|
156 |
||
157 |
!ArithmeticValue methodsFor:'double dispatching'! |
|
158 |
||
4379
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
159 |
sumFromQDouble:aQDouble |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
160 |
"aQDouble does not know how to add the receiver - |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
161 |
retry the operation by coercing to higher generality" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
162 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
163 |
^ aQDouble retry:#+ coercing:self |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
164 |
|
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
165 |
"Created: / 13-06-2017 / 08:54:27 / cg" |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
166 |
! ! |
e547154fa694
double dispatch for QDoubles
Claus Gittinger <cg@exept.de>
parents:
4365
diff
changeset
|
167 |
|
4448 | 168 |
!Block methodsFor:'Compatibility-Dolphin'! |
169 |
||
170 |
deferredValue |
|
171 |
"Dolphin compatibility method - do not use in new code. |
|
172 |
Dolphin's alias for futureValue" |
|
173 |
||
174 |
^ Future new block:self |
|
175 |
||
176 |
"Modified: / 04-10-2011 / 14:56:27 / cg" |
|
177 |
! ! |
|
178 |
||
179 |
!Block methodsFor:'Compatibility-Dolphin'! |
|
180 |
||
181 |
deferredValueAt:priority |
|
182 |
"Dolphin compatibility method - do not use in new code. |
|
183 |
Dolphin's alias for futureValue" |
|
184 |
||
185 |
^ Future new |
|
186 |
priority:priority block:self |
|
187 |
||
188 |
"Created: / 04-10-2011 / 14:55:56 / cg" |
|
189 |
! ! |
|
190 |
||
191 |
!Block methodsFor:'parallel evaluation'! |
|
192 |
||
193 |
futureValue |
|
194 |
"Fork a synchronised evaluation of myself. |
|
195 |
Starts the evaluation in parallel now, but synchronizes |
|
196 |
any access to wait until the result is computed." |
|
197 |
||
198 |
^ Future new block:self |
|
199 |
! ! |
|
200 |
||
201 |
!Block methodsFor:'parallel evaluation'! |
|
202 |
||
203 |
futureValue:aValue |
|
204 |
"Fork a synchronised evaluation of myself. |
|
205 |
Starts the evaluation in parallel now, but synchronizes |
|
206 |
any access to wait until the result is computed." |
|
207 |
||
208 |
^ Future new block:self value:aValue |
|
209 |
! ! |
|
210 |
||
211 |
!Block methodsFor:'parallel evaluation'! |
|
212 |
||
213 |
futureValue:aValue value:anotherValue |
|
214 |
"Fork a synchronised evaluation of myself. |
|
215 |
Starts the evaluation in parallel now, but synchronizes |
|
216 |
any access to wait until the result is computed." |
|
217 |
||
218 |
^ Future new |
|
219 |
block:self |
|
220 |
value:aValue |
|
221 |
value:anotherValue |
|
222 |
! ! |
|
223 |
||
224 |
!Block methodsFor:'parallel evaluation'! |
|
225 |
||
226 |
futureValue:aValue value:anotherValue value:bValue |
|
227 |
"Fork a synchronised evaluation of myself. |
|
228 |
Starts the evaluation in parallel now, but synchronizes |
|
229 |
any access to wait until the result is computed." |
|
230 |
||
231 |
^ Future new |
|
232 |
block:self |
|
233 |
value:aValue |
|
234 |
value:anotherValue |
|
235 |
value:bValue |
|
236 |
! ! |
|
237 |
||
238 |
!Block methodsFor:'parallel evaluation'! |
|
239 |
||
240 |
futureValueWithArguments:anArray |
|
241 |
"Fork a synchronised evaluation of myself. |
|
242 |
Starts the evaluation in parallel now, but synchronizes |
|
243 |
any access to wait until the result is computed." |
|
244 |
||
245 |
^ Future new |
|
246 |
block:self |
|
247 |
valueWithArguments:anArray |
|
248 |
||
249 |
"Modified (format): / 04-10-2011 / 14:55:40 / cg" |
|
250 |
! ! |
|
251 |
||
252 |
!Block methodsFor:'parallel evaluation'! |
|
253 |
||
254 |
lazyValue |
|
4797 | 255 |
"Return a lazy value object, evaluating myself. |
256 |
Only computes when the result is requested." |
|
4448 | 257 |
|
258 |
^ Lazy new block:self |
|
4797 | 259 |
|
260 |
"Modified (comment): / 09-02-2019 / 15:59:29 / Claus Gittinger" |
|
4448 | 261 |
! ! |
262 |
||
263 |
!Block methodsFor:'parallel evaluation'! |
|
264 |
||
265 |
lazyValue:aValue |
|
4797 | 266 |
"Return a lazy value object, evaluating myself. |
267 |
Only computes when the result is requested." |
|
4448 | 268 |
|
269 |
^ Lazy new block:self value:aValue |
|
4797 | 270 |
|
271 |
"Modified (comment): / 09-02-2019 / 16:00:02 / Claus Gittinger" |
|
4448 | 272 |
! ! |
273 |
||
274 |
!Block methodsFor:'parallel evaluation'! |
|
275 |
||
276 |
lazyValue:aValue value:anotherValue |
|
4797 | 277 |
"Return a lazy value object, evaluating myself. |
278 |
Only computes when the result is requested." |
|
4448 | 279 |
|
280 |
^ Lazy new |
|
4797 | 281 |
block:self |
282 |
value:aValue |
|
283 |
value:anotherValue |
|
284 |
||
285 |
"Modified (comment): / 09-02-2019 / 16:00:05 / Claus Gittinger" |
|
4448 | 286 |
! ! |
287 |
||
288 |
!Block methodsFor:'parallel evaluation'! |
|
289 |
||
290 |
lazyValue:aValue value:anotherValue value:bValue |
|
4797 | 291 |
"Return a lazy value object, evaluating myself. |
292 |
Only computes when the result is requested." |
|
4448 | 293 |
|
294 |
^ Lazy new |
|
4797 | 295 |
block:self |
296 |
value:aValue |
|
297 |
value:anotherValue |
|
298 |
value:bValue |
|
299 |
||
300 |
"Modified (comment): / 09-02-2019 / 16:00:08 / Claus Gittinger" |
|
4448 | 301 |
! ! |
302 |
||
303 |
!Block methodsFor:'parallel evaluation'! |
|
304 |
||
305 |
lazyValueWithArguments:anArray |
|
4797 | 306 |
"Return a lazy value object, evaluating myself. |
307 |
Only computes when the result is requested." |
|
4448 | 308 |
|
309 |
^ Lazy new block:self valueWithArguments:anArray |
|
4797 | 310 |
|
311 |
"Modified (comment): / 09-02-2019 / 16:00:12 / Claus Gittinger" |
|
4448 | 312 |
! ! |
313 |
||
314 |
!Block methodsFor:'process creation'! |
|
315 |
||
316 |
promise |
|
317 |
"create a promise on the receiver. The promise will evaluate the |
|
318 |
receiver and promise to return the value with the #value message. |
|
319 |
The evaluation will be performed as a separate process. |
|
320 |
Asking the promise for its value will either block the asking process |
|
321 |
(if the evaluation has not yet been finished) or return the value |
|
322 |
immediately." |
|
323 |
||
324 |
^ Promise value:self |
|
325 |
||
326 |
" |
|
327 |
|p| |
|
328 |
||
329 |
p := [1000 factorial] promise. |
|
330 |
'do something else ...'. |
|
331 |
p value |
|
332 |
" |
|
333 |
! ! |
|
334 |
||
335 |
!Block methodsFor:'process creation'! |
|
336 |
||
337 |
promiseAt:prio |
|
338 |
"create a promise on the receiver. The promise will evaluate the |
|
339 |
receiver and promise to return the value with the #value message. |
|
340 |
The evaluation will be performed as a separate process running at prio. |
|
341 |
Asking the promise for its value will either block the asking process |
|
342 |
(if the evaluation has not yet been finished) or return the value |
|
343 |
immediately." |
|
344 |
||
345 |
^ Promise value:self priority:prio |
|
346 |
! ! |
|
347 |
||
2288 | 348 |
!CharacterArray methodsFor:'matching - phonetic'! |
2199
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 |
asKoelnerPhoneticCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
351 |
"return a koelner phonetic code. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
352 |
The koelnerPhonetic code is for the german language what the soundex code is for english; |
2303 | 353 |
it returns simular strings for similar sounding words. |
354 |
There are some differences to soundex, though: |
|
355 |
its length is not limited to 4, but depends on the length of the original string; |
|
356 |
it does not start with the first character of the input. |
|
2288 | 357 |
|
358 |
Caveat: this phonetic code is especially suited for german words. |
|
2303 | 359 |
Please have a look at the other phonetic comparison operators found |
360 |
in PhoneticStringUtilities." |
|
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
361 |
|
2303 | 362 |
^ PhoneticStringUtilities koelnerPhoneticCodeOf:self |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
363 |
|
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 |
#( |
3715 | 366 |
'Müller' |
2303 | 367 |
'Miller' |
368 |
'Mueller' |
|
3715 | 369 |
'Mühler' |
370 |
'Mühlherr' |
|
371 |
'Mülherr' |
|
2303 | 372 |
'Myler' |
373 |
'Millar' |
|
374 |
'Myller' |
|
3715 | 375 |
'Müllar' |
376 |
'Müler' |
|
2303 | 377 |
'Muehler' |
3715 | 378 |
'Mülller' |
379 |
'Müllerr' |
|
2303 | 380 |
'Muehlherr' |
381 |
'Muellar' |
|
382 |
'Mueler' |
|
3715 | 383 |
'Mülleer' |
2303 | 384 |
'Mueller' |
3715 | 385 |
'Nüller' |
2303 | 386 |
'Nyller' |
387 |
'Niler' |
|
388 |
'Czerny' |
|
389 |
'Tscherny' |
|
390 |
'Czernie' |
|
391 |
'Tschernie' |
|
392 |
'Schernie' |
|
393 |
'Scherny' |
|
394 |
'Scherno' |
|
395 |
'Czerne' |
|
396 |
'Zerny' |
|
397 |
'Tzernie' |
|
398 |
'Breschnew' |
|
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
399 |
) do:[:w | |
2303 | 400 |
Transcript show:w; show:'->'; showCR:(w asKoelnerPhoneticCode) |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
401 |
]. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
402 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
403 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
404 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
405 |
'Breschnew' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
406 |
'Breschnew' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
407 |
'Breschneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
408 |
'Braeschneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
409 |
'Braessneff' asKoelnerPhoneticCode -> '17863' |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
410 |
'Pressneff' asKoelnerPhoneticCode -> '17863' |
3715 | 411 |
'Presznäph' asKoelnerPhoneticCode -> '17863' |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
412 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
413 |
! ! |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
414 |
|
2288 | 415 |
!CharacterArray methodsFor:'matching - phonetic'! |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
416 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
417 |
asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
418 |
"return a soundex phonetic code or nil. |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
419 |
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
|
420 |
tool when searching for words where the correct spelling is unknown. |
4190 | 421 |
(read Knuth or search the web if you don't know what a soundex code is). |
2288 | 422 |
|
2337
755696d72648
comment/format in: #asSoundexCode
Claus Gittinger <cg@exept.de>
parents:
2303
diff
changeset
|
423 |
Caveat: 'similar sounding words' means: 'similar sounding in ENGLISH' |
4190 | 424 |
Please have a look at the other phonetic comparison operators found |
425 |
in PhoneticStringUtilities." |
|
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
426 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
427 |
^ PhoneticStringUtilities soundexCodeOf:self |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
428 |
|
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
429 |
" |
2303 | 430 |
'claus' asSoundexCode |
2199
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
431 |
'clause' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
432 |
'close' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
433 |
'smalltalk' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
434 |
'smaltalk' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
435 |
'smaltak' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
436 |
'smaltok' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
437 |
'smoltok' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
438 |
'aa' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
439 |
'by' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
440 |
'bab' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
441 |
'bob' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
442 |
'bop' asSoundexCode |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
443 |
" |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
444 |
! ! |
a9d3b1aa9f03
phonetic stuff extraced into libbasic2
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
445 |
|
2241 | 446 |
!CharacterArray methodsFor:'printing & storing'! |
447 |
||
2303 | 448 |
printf:args |
449 |
"Format and print the receiver with <args> formatted in C style, |
|
2295 | 450 |
as specified in the Unix C-language manual page for printf(3). |
3114 | 451 |
Return the resulting string (i.e actually, this is more like an sprintf). |
4619 | 452 |
For smalltalk specific formats, |
453 |
see documentation in PrintfScanf >> format_printf. |
|
2241 | 454 |
For copyright information, see goodies/String-printf_scanf.chg" |
2303 | 455 |
|
2241 | 456 |
|aStream| |
457 |
||
3538 | 458 |
aStream := CharacterWriteStream on:(self species uninitializedNew:self size). |
2260 | 459 |
self printf:args on:aStream. |
2241 | 460 |
^ aStream contents |
461 |
||
462 |
" |
|
3796 | 463 |
('%05x %d %f %o' printf:{ 123. 234*5. 1.234. 8r377 } ) |
2303 | 464 |
Transcript showCR:('%05x %d %f %o' printf:{ 123. 234*5. 1.234. 8r377 } ) |
2256 | 465 |
" |
466 |
||
467 |
" |
|
2241 | 468 |
Transcript showCR: 'Some examples:'!! |
469 |
||
470 |
Transcript show:'''%#x %#X %03o%*.*s'' printf: #(16rABCD 16rEF 5 9 5 ''ghijklmn'') = .'. |
|
2303 | 471 |
Transcript show: ('%#x %#X %03o%*.*s' printf: #(16rABCD 16rEF 5 9 5 'ghijklmn')). |
2241 | 472 |
Transcript showCR: '.' |
473 |
||
474 |
Transcript show: '''%- 10.4s%.2e'' printf: (Array with: ''abcdefghijkl'' with: Float pi) = .'. |
|
2303 | 475 |
Transcript show: ('%- 10.4s%.2e' printf: (Array with: 'abcdefghijkl' with: Float pi)). |
2241 | 476 |
Transcript showCR: '.' |
477 |
||
478 |
Transcript show: '''%8.3f'' printf: (Array with: 200 sqrt negated) = .'. |
|
479 |
Transcript show: ('%8.3f' printf: (Array with: 200 sqrt negated)). |
|
480 |
Transcript showCR: '.' |
|
481 |
||
482 |
Transcript show: '''%c'' printf: #(16r41) = .'. |
|
483 |
Transcript show: ('%c' printf: #(16r41)). |
|
484 |
Transcript showCR: '.' |
|
485 |
||
486 |
Transcript show: '''%f%2s%s%s%s'' sscanf: ''237.0 this is a test'' = '. |
|
487 |
Transcript showCR: ('%f%2s%s%s%s' sscanf: '237.0 this is a test') printString. |
|
488 |
||
489 |
Transcript show: '''%d%f%s'' sscanf: ''25 54.32e-01 monday'' = '. |
|
490 |
Transcript showCR: ('%d%f%s' sscanf: '25 54.32e-01 monday') printString. |
|
491 |
||
492 |
Transcript show: '''%f%*f %8[A-F0-9]%c%d 0x%x%f'' sscanf: ''12.45 1048.73 AE40Z527 0x75BCD15 34'' = '. |
|
493 |
Transcript showCR: ('%f%*f %8[A-F0-9]%c%d 0x%x%f' sscanf: '12.45 1048.73 AE40Z527 0x75BCD15 34') printString. |
|
494 |
" |
|
4528 | 495 |
|
496 |
"Modified (comment): / 14-11-2017 / 22:58:01 / cg" |
|
2241 | 497 |
! ! |
498 |
||
499 |
!CharacterArray methodsFor:'printing & storing'! |
|
500 |
||
2260 | 501 |
printf:args on:outStream |
502 |
"Format and print the receiver on <outStream> with <args> |
|
503 |
formatted in C style, as specified in the Unix C-language manual page for printf(3). |
|
4619 | 504 |
For smalltalk specific formats, |
505 |
see documentation in PrintfScanf >> format_printf. |
|
2260 | 506 |
For copyright information, see goodies/String-printf_scanf.chg" |
2303 | 507 |
|
4418 | 508 |
PrintfScanf printf:self on:outStream arguments: args |
509 |
||
510 |
" |
|
511 |
'%e' printf:{ 1234.567 ] on:Transcript |
|
512 |
||
513 |
'%10s%3d\n' printf:{ 'hello' . 12 } on:Transcript |
|
514 |
'%10s%3d\n' printf:{ '1234567890' . 12 } on:Transcript |
|
2260 | 515 |
|
4418 | 516 |
like C's printf, a longer datum may be formatted wider than the formatspec says: |
517 |
||
518 |
'%10s%3d\n' printf:{ '12345678901234' . 12 } on:Transcript |
|
519 |
||
520 |
'%10s%3d\n' printf:{ 'hello' . 12 } on:Transcript |
|
521 |
'%10s%03d\n' printf:{ 'hello' . 12 } on:Transcript |
|
522 |
" |
|
523 |
||
4528 | 524 |
"Modified (comment): / 14-11-2017 / 22:57:58 / cg" |
2260 | 525 |
! ! |
526 |
||
527 |
!CharacterArray methodsFor:'printing & storing'! |
|
528 |
||
2303 | 529 |
printfWith:arg1 |
2295 | 530 |
"Format and print the receiver with <arg1> formatted in C style, |
531 |
as specified in the Unix C-language manual page for printf(3). |
|
4528 | 532 |
Return the resulting string (i.e actually, this is more like an sprintf). |
4619 | 533 |
For smalltalk specific formats, |
534 |
see documentation in PrintfScanf >> format_printf" |
|
2303 | 535 |
|
2256 | 536 |
^ self printf:(Array with:arg1) |
537 |
||
538 |
" |
|
3796 | 539 |
('%05x' printfWith:123) |
2303 | 540 |
Transcript showCR:('%05x' printfWith:123) |
2256 | 541 |
" |
4528 | 542 |
|
543 |
"Modified (comment): / 14-11-2017 / 22:58:10 / cg" |
|
2256 | 544 |
! ! |
545 |
||
546 |
!CharacterArray methodsFor:'printing & storing'! |
|
547 |
||
2303 | 548 |
printfWith:arg1 with:arg2 |
549 |
"Format and print the receiver with <argI> formatted in C style, |
|
2295 | 550 |
as specified in the Unix C-language manual page for printf(3). |
4528 | 551 |
Return the resulting string (i.e actually, this is more like an sprintf). |
4619 | 552 |
For smalltalk specific formats, see documentation in PrintfScanf >> format_printf." |
2303 | 553 |
|
2256 | 554 |
^ self printf:(Array with:arg1 with:arg2) |
555 |
||
556 |
" |
|
2303 | 557 |
Transcript showCR:('%d %05x' printfWith:123 with:234) |
5234 | 558 |
('%d %05x' printfWith:123 with:234) |
559 |
('%d%02d' printfWith:2004 with:9) |
|
2256 | 560 |
" |
4528 | 561 |
|
562 |
"Modified (comment): / 14-11-2017 / 22:58:16 / cg" |
|
2256 | 563 |
! ! |
564 |
||
565 |
!CharacterArray methodsFor:'printing & storing'! |
|
566 |
||
567 |
printfWith:arg1 with:arg2 with:arg3 |
|
2303 | 568 |
"Format and print the receiver with <argI> formatted in C style, |
2295 | 569 |
as specified in the Unix C-language manual page for printf(3). |
4528 | 570 |
Return the resulting string (i.e actually, this is more like an sprintf). |
4619 | 571 |
For smalltalk specific formats, see documentation in PrintfScanf >> format_printf." |
2303 | 572 |
|
2256 | 573 |
^ self printf:(Array with:arg1 with:arg2 with:arg3) |
574 |
||
575 |
" |
|
2303 | 576 |
Transcript showCR:('%d %05x %08o' printfWith:123 with:234 with:345) |
2256 | 577 |
" |
4528 | 578 |
|
579 |
"Modified (comment): / 14-11-2017 / 22:58:20 / cg" |
|
2256 | 580 |
! ! |
581 |
||
582 |
!CharacterArray methodsFor:'printing & storing'! |
|
583 |
||
584 |
printfWith:arg1 with:arg2 with:arg3 with:arg4 |
|
2303 | 585 |
"Format and print the receiver with <argI> formatted in C style, |
2295 | 586 |
as specified in the Unix C-language manual page for printf(3). |
4528 | 587 |
Return the resulting string (i.e actually, this is more like an sprintf). |
4619 | 588 |
For smalltalk specific formats, see documentation in PrintfScanf >> format_printf." |
2303 | 589 |
|
2256 | 590 |
^ self printf:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
591 |
||
592 |
" |
|
2303 | 593 |
Transcript showCR:('%d %05x %08o %b' printfWith:123 with:234 with:345 with:123) |
2256 | 594 |
" |
4528 | 595 |
|
596 |
"Modified (comment): / 14-11-2017 / 22:58:23 / cg" |
|
597 |
! ! |
|
598 |
||
599 |
!CharacterArray methodsFor:'printing & storing'! |
|
600 |
||
601 |
printfWith:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
602 |
"Format and print the receiver with <argI> formatted in C style, |
|
603 |
as specified in the Unix C-language manual page for printf(3). |
|
604 |
Return the resulting string (i.e actually, this is more like an sprintf). |
|
4619 | 605 |
For smalltalk specific formats, see documentation in PrintfScanf >> format_printf." |
4528 | 606 |
|
607 |
^ self printf:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
608 |
||
609 |
" |
|
610 |
Transcript showCR:('%d %05x %08o %b' printfWith:123 with:234 with:345 with:123) |
|
611 |
" |
|
612 |
||
613 |
"Modified (comment): / 14-11-2017 / 22:58:28 / cg" |
|
2256 | 614 |
! ! |
615 |
||
616 |
!CharacterArray methodsFor:'printing & storing'! |
|
617 |
||
2241 | 618 |
printf_formatArgCount |
619 |
"Return the number of arguments required/produced if the receiver is interpreted |
|
620 |
as a printf/scanf format control string. |
|
4528 | 621 |
For smalltalk specific formats, see documentation in PrintfScanf. |
2241 | 622 |
For copyright information, see goodies/String-printf_scanf.chg" |
2303 | 623 |
|
4418 | 624 |
^ PrintfScanf formatArgCountFor:self. |
2241 | 625 |
|
4418 | 626 |
"Modified: / 19-06-2017 / 16:54:10 / cg" |
4528 | 627 |
"Modified (comment): / 14-11-2017 / 22:58:34 / cg" |
2241 | 628 |
! ! |
629 |
||
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
630 |
!CharacterArray methodsFor:'private'! |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
631 |
|
4418 | 632 |
printf_printArgFrom:formatStream to:outStream withData:argStream |
633 |
<resource: #obsolete> |
|
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
634 |
"Interpret the required number of arguments from <argStream> |
4418 | 635 |
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
|
636 |
Place the interpretation on <outStream>. |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
637 |
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
|
638 |
specified in the Unix C-language manual page for printf(3). |
4418 | 639 |
<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
|
640 |
$%, 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
|
641 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
642 |
Return when the conversion control string is consumed. |
4418 | 643 |
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
|
644 |
|
4418 | 645 |
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
|
646 |
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
|
647 |
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
|
648 |
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
|
649 |
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
|
650 |
|
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
651 |
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
|
652 |
|
4418 | 653 |
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
|
654 |
|
4418 | 655 |
"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
|
656 |
! ! |
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
657 |
|
2241 | 658 |
!CharacterArray methodsFor:'printing & storing'! |
659 |
||
2260 | 660 |
printf_printOn:outStream withData:args |
661 |
<resource: #obsolete> |
|
2303 | 662 |
|
2241 | 663 |
"Format and print the receiver on <outStream> with <args> |
664 |
formatted in C style, as specified in the Unix C-language manual page for printf(3). |
|
665 |
||
666 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
667 |
||
2260 | 668 |
self obsoleteMethodWarning:'use printf:on:'. |
669 |
self printf:args on:outStream |
|
2241 | 670 |
! ! |
671 |
||
672 |
!CharacterArray methodsFor:'converting'! |
|
673 |
||
4473 | 674 |
scanf:dataStreamOrString |
2241 | 675 |
"Return a Collection of objects found in the Character Stream |
2303 | 676 |
<dataStream> as interpreted according to the receiver. |
2241 | 677 |
The receiver is assumed to be a conversion control string as |
678 |
specified in the Unix C-language manual page for scanf(3). |
|
679 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 680 |
|
4473 | 681 |
|dataStream| |
2241 | 682 |
|
4473 | 683 |
dataStream := dataStreamOrString readStream. |
684 |
^ PrintfScanf scanf:self fromStream:dataStream |
|
685 |
||
686 |
"/ |results format char| |
|
687 |
"/ |
|
688 |
"/ results := OrderedCollection new. |
|
689 |
"/ format := ReadStream on:self. |
|
690 |
"/ [ format atEnd ] whileFalse:[ |
|
691 |
"/ char := format next. |
|
692 |
"/ (char == Character space or:[ char == Character tab ]) ifTrue:[ |
|
693 |
"/ dataStream skipSeparators. |
|
694 |
"/ format skipSeparators |
|
695 |
"/ ]. |
|
696 |
"/ char == $% ifTrue:[ |
|
697 |
"/ PrintfScanf scanArgFrom:dataStream to:results format:format. |
|
698 |
"/ ] ifFalse:[ |
|
699 |
"/ dataStream peekFor:char |
|
700 |
"/ ] |
|
701 |
"/ ]. |
|
702 |
"/ ^ results |
|
2241 | 703 |
|
704 |
" |
|
2303 | 705 |
'%d %x' scanf:(ReadStream on:'1234 ff00') |
4473 | 706 |
'%d %s' scanf:(ReadStream on:'1234 ff00') |
707 |
'%d %b' scanf:(ReadStream on:'1234 1111') |
|
708 |
'%d %f' scanf:(ReadStream on:'1234 1111') |
|
709 |
'%d %f' scanf:(ReadStream on:'1234 1111.2345') |
|
710 |
'%d %q' scanf:(ReadStream on:'1234 1111.2345') |
|
2241 | 711 |
" |
4473 | 712 |
|
713 |
"Modified: / 14-07-2017 / 11:11:49 / cg" |
|
2241 | 714 |
! ! |
715 |
||
716 |
!CharacterArray methodsFor:'private'! |
|
717 |
||
2303 | 718 |
scanf_scanArgFrom:dataStream to:collection format:format |
4418 | 719 |
<resource: #obsolete> |
2241 | 720 |
"Add to <collection> an object who's representation is found |
721 |
in <dataStream> interpreted according to the conversion |
|
2303 | 722 |
control string in the Stream <format>. |
723 |
<format> is assumed to be positioned just past a $%, and a complete control |
|
2241 | 724 |
string is assumed available. |
725 |
||
726 |
Return when the conversion control string is consumed. Leave |
|
727 |
<format> pointing past the last character in the conversion |
|
728 |
control string, leave <dataStream> pointing past any width |
|
729 |
specified in <format>, or at the first character that doesn't |
|
730 |
make sense for the <format>. |
|
731 |
||
732 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 733 |
|
4473 | 734 |
PrintfScanf scanArgFrom:dataStream to:collection format:format. |
2256 | 735 |
|
736 |
" |
|
2303 | 737 |
'%d %x' sscanf:'1234 ff00' |
738 |
'%d %x %b' sscanf:'1234 ff00 1001' |
|
2256 | 739 |
" |
2679
cfab54d30fcc
changed: #scanArgFrom:to:format:
Claus Gittinger <cg@exept.de>
parents:
2582
diff
changeset
|
740 |
|
4473 | 741 |
"Modified: / 14-07-2017 / 11:09:35 / cg" |
2241 | 742 |
! ! |
743 |
||
744 |
!CharacterArray methodsFor:'converting'! |
|
745 |
||
2303 | 746 |
sscanf:string |
2241 | 747 |
"Return a Collection of objects found in <string> as |
2303 | 748 |
interpreted according to the receiver. |
2241 | 749 |
The receiver is assumed to be a conversion control string as |
750 |
specified in the Unix C-language manual page for scanf(3). |
|
751 |
For copyright information, see goodies/String-printf_scanf.chg" |
|
2303 | 752 |
|
2241 | 753 |
^ self scanf:(ReadStream on:string) |
754 |
||
755 |
" |
|
2303 | 756 |
'%d %x' sscanf:'1234 ff00' |
757 |
'%d %x %b' sscanf:'1234 ff00 1001' |
|
2241 | 758 |
" |
759 |
! ! |
|
760 |
||
4714 | 761 |
!CharacterArray methodsFor:'Compatibility-Squeak'! |
762 |
||
763 |
urlDecoded |
|
764 |
"decode %xx form. This is the opposite of #urlEncoded" |
|
765 |
||
766 |
^ HTMLUtilities urlDecoded:self |
|
767 |
||
768 |
" |
|
769 |
'abc%61def' unescapePercents |
|
770 |
'abc%61def' urlDecoded |
|
771 |
||
772 |
(HTMLUtilities urlEncoded:'_-.*Frankfurt(Main) Hbf') unescapePercents |
|
773 |
(HTMLUtilities urlEncoded:'_-.*Frankfurt(Main) Hbf') urlDecoded |
|
774 |
||
775 |
(HTMLUtilities urlEncoded:'-_.*%exept ex+pecco;') unescapePercents |
|
776 |
(HTMLUtilities urlEncoded:'-_.*%exept+ex+pecco;') urlDecoded |
|
777 |
" |
|
778 |
||
779 |
"Created: / 26-08-2018 / 12:41:49 / Claus Gittinger" |
|
780 |
! ! |
|
781 |
||
782 |
!CharacterArray methodsFor:'Compatibility-Squeak'! |
|
783 |
||
784 |
urlEncoded |
|
785 |
"encode into %xx form. This is the opposite of #urlDecoded" |
|
786 |
||
787 |
^ HTMLUtilities urlEncoded:self |
|
788 |
||
789 |
" |
|
790 |
'abcäöüdef' urlEncoded urlDecoded |
|
791 |
'abc%def' urlEncoded urlDecoded |
|
792 |
||
793 |
('_-.*Frankfurt(Main) Hbf' urlEncoded) unescapePercents |
|
794 |
('_-.*Frankfurt(Main) Hbf' urlEncoded) urlDecoded |
|
795 |
||
796 |
('-_.*%exept ex+pecco;' urlEncoded) unescapePercents |
|
797 |
('-_.*%exept+ex+pecco;' urlEncoded) urlDecoded |
|
798 |
" |
|
799 |
||
800 |
"Created: / 26-08-2018 / 13:03:03 / Claus Gittinger" |
|
801 |
! ! |
|
802 |
||
4365
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
803 |
!Collection methodsFor:'converting'! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
804 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
805 |
asHalfFloatArray |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
806 |
"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
|
807 |
(which must convert to 16bit half-floats)." |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
808 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
809 |
^ self asArrayOfType:HalfFloatArray |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
810 |
! ! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
811 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
812 |
!Collection methodsFor:'converting'! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
813 |
|
4400 | 814 |
asIdentitySkipList |
815 |
"Answer a IdentitySkipList whose elements are the elements of the |
|
816 |
receiver. The sort order is the default less than or equal." |
|
817 |
||
818 |
^ self as: IdentitySkipList |
|
819 |
! ! |
|
820 |
||
821 |
!Collection methodsFor:'converting'! |
|
822 |
||
4365
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
823 |
asList |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
824 |
"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
|
825 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
826 |
^ self addAllTo:(List new:self size) |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
827 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
828 |
"Created: 14.2.1997 / 16:25:23 / cg" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
829 |
! ! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
830 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
831 |
!Collection methodsFor:'converting'! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
832 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
833 |
asRunArray |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
834 |
"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
|
835 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
836 |
^ RunArray from:self. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
837 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
838 |
"/ |runs lastElement occurrences| |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
839 |
"/ |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
840 |
"/ runs := RunArray new. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
841 |
"/ occurrences := 0. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
842 |
"/ self do:[:each | |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
843 |
"/ each == lastElement ifTrue:[ |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
844 |
"/ occurrences := occurrences + 1 |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
845 |
"/ ] ifFalse:[ |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
846 |
"/ runs add:lastElement withOccurrences:occurrences. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
847 |
"/ occurrences := 1. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
848 |
"/ lastElement := each |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
849 |
"/ ]. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
850 |
"/ ]. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
851 |
"/ occurrences ~~ 0 ifTrue:[ |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
852 |
"/ runs add:lastElement withOccurrences:occurrences |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
853 |
"/ ]. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
854 |
"/ ^ runs |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
855 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
856 |
" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
857 |
#(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
|
858 |
" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
859 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
860 |
"Modified: / 7.4.1998 / 09:50:54 / cg" |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
861 |
! ! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
862 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
863 |
!Collection methodsFor:'converting'! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
864 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
865 |
asSharedCollection |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
866 |
"return a shared collection on the receiver. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
867 |
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
|
868 |
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
|
869 |
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
|
870 |
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
|
871 |
tuned for this kind of operation." |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
872 |
|
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
873 |
^ SharedCollection for:self. |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
874 |
! ! |
c166b1f7825c
Move methods from Collection to libbasic2
Stefan Vogel <sv@exept.de>
parents:
4202
diff
changeset
|
875 |
|
4400 | 876 |
!Collection methodsFor:'converting'! |
877 |
||
878 |
asSkipList |
|
879 |
"Answer a SkipList whose elements are the elements of the |
|
880 |
receiver. The sort order is the default less than or equal." |
|
881 |
||
882 |
^ self as: SkipList |
|
883 |
! ! |
|
884 |
||
885 |
!Collection methodsFor:'converting'! |
|
886 |
||
887 |
asSkipList: aSortBlock |
|
888 |
"Answer a SkipList whose elements are the elements of the |
|
889 |
receiver. The sort order is defined by the argument, aSortBlock." |
|
890 |
||
891 |
| skipList | |
|
892 |
skipList := SkipList new: self size sortBlock: aSortBlock. |
|
893 |
skipList addAll: self. |
|
894 |
^ skipList |
|
895 |
||
896 |
"Modified (comment): / 18-06-2017 / 22:40:10 / cg" |
|
897 |
! ! |
|
898 |
||
2237 | 899 |
!Float methodsFor:'private'! |
900 |
||
2303 | 901 |
absDecimalPrintOn:aStream digits:digits |
2237 | 902 |
"Place a string representation of the receiver's abs value |
903 |
on <aStream> using <digits> significant digits, using decimal notation. |
|
904 |
This is a helper for printf." |
|
905 |
||
4429 | 906 |
<resource: #obsolete> |
907 |
PrintfScanf absDecimalPrintFloat:self on:aStream digits:digits. |
|
2237 | 908 |
|
4429 | 909 |
"Modified: / 20-06-2017 / 11:49:15 / cg" |
2237 | 910 |
! ! |
911 |
||
912 |
!Float methodsFor:'private'! |
|
913 |
||
2303 | 914 |
absPrintOn:aStream digits:digits |
915 |
"Place a string representation of the receiver's abs value on <aStream> using |
|
2237 | 916 |
<digits> significant digits. |
917 |
This is a helper for printf." |
|
2303 | 918 |
|
4429 | 919 |
<resource: #obsolete> |
4418 | 920 |
PrintfScanf absPrintFloat:self on:aStream digits:digits |
921 |
||
4429 | 922 |
"Modified: / 20-06-2017 / 11:49:11 / cg" |
2237 | 923 |
! ! |
924 |
||
925 |
!Float methodsFor:'private'! |
|
926 |
||
2303 | 927 |
absScientificPrintOn:aStream digits:digits |
2237 | 928 |
"Place a string representation of the receiver's abs value on <aStream> using <digits> significant |
929 |
digits, using scientific notation. |
|
930 |
This is a helper for printf." |
|
2303 | 931 |
|
4429 | 932 |
<resource: #obsolete> |
4418 | 933 |
PrintfScanf absScientificPrintFloat:self on:aStream digits:digits. |
2237 | 934 |
|
4418 | 935 |
"Modified: / 19-06-2017 / 14:59:56 / cg" |
4429 | 936 |
"Modified (format): / 20-06-2017 / 11:49:07 / cg" |
2237 | 937 |
! ! |
938 |
||
4381 | 939 |
!Float methodsFor:'coercing & converting'! |
940 |
||
5325 | 941 |
asIEEEFloat |
942 |
"return an IEEE soft float with same value as receiver" |
|
943 |
||
944 |
^ IEEEFloat fromFloat:self |
|
945 |
||
946 |
" |
|
947 |
123 asFloat asIEEEFloat |
|
948 |
0 asShortFloat asIEEEFloat |
|
949 |
0.0 asIEEEFloat |
|
950 |
" |
|
951 |
||
952 |
! ! |
|
953 |
||
954 |
!Float methodsFor:'coercing & converting'! |
|
955 |
||
5293
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
956 |
asOctaFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
957 |
"return an octaFloat with same value as receiver" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
958 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
959 |
^ OctaFloat fromFloat:self |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
960 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
961 |
" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
962 |
123 asFloat asOctaFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
963 |
0 asFloat asOctaFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
964 |
0.0 asOctaFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
965 |
" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
966 |
! ! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
967 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
968 |
!Float methodsFor:'coercing & converting'! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
969 |
|
4381 | 970 |
asQDouble |
971 |
"return a QDouble with my value" |
|
972 |
||
973 |
^ QDouble fromFloat:self |
|
974 |
||
975 |
" |
|
976 |
1.0 asQDouble |
|
977 |
" |
|
978 |
||
979 |
"Created: / 13-06-2017 / 16:48:57 / cg" |
|
980 |
! ! |
|
981 |
||
5293
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
982 |
!Float methodsFor:'coercing & converting'! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
983 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
984 |
asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
985 |
"return a quadFloat with same value as receiver" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
986 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
987 |
^ QuadFloat fromFloat:self |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
988 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
989 |
" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
990 |
123 asFloat asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
991 |
0 asFloat asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
992 |
0.0 asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
993 |
" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
994 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
995 |
"Created: / 07-06-2019 / 02:28:26 / Claus Gittinger" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
996 |
"Modified (comment): / 10-06-2019 / 21:51:04 / Claus Gittinger" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
997 |
! ! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
998 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
999 |
!Fraction methodsFor:'coercing & converting'! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1000 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1001 |
asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1002 |
"return a QuadFloat with (approximately) my value. |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1003 |
Since floats have a limited precision, you usually loose bits when doing this." |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1004 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1005 |
|num den numShift denShift numBits rslt| |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1006 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1007 |
(numerator class == SmallInteger and:[denominator class == SmallInteger]) ifTrue:[ |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1008 |
^ (numerator asQuadFloat) / (denominator asQuadFloat) |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1009 |
]. |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1010 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1011 |
"Do it the hard way: reduce magnitude and undo reduction on the quotient" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1012 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1013 |
numBits := QuadFloat precision * 2. "number of bits to preserve (conservative)" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1014 |
num := numerator abs. |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1015 |
numShift := numBits - num highBit. "(num highBit - bits) negated" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1016 |
numShift < 0 ifTrue:[num := num bitShift:numShift] ifFalse:[ numShift := 0]. |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1017 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1018 |
den := denominator. |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1019 |
denShift := numBits - den highBit. "(den highBit - bits) negated" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1020 |
denShift < 0 ifTrue:[den := den bitShift:denShift] ifFalse:[denShift := 0]. |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1021 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1022 |
rslt := (num asQuadFloat / den asQuadFloat) * (2 raisedToInteger:denShift-numShift). |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1023 |
numerator negative ifTrue:[ ^ rslt negated ]. |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1024 |
^ rslt. |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1025 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1026 |
" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1027 |
(5/9) asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1028 |
(-5/9) asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1029 |
(Fraction basicNew setNumerator:500000000000 denominator:900000000000) asQuadFloat = (5/9) asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1030 |
(Fraction basicNew setNumerator:500000000001 denominator:900000000000) asQuadFloat = (5/9) asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1031 |
(500000000001/900000000000) asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1032 |
(-500000000001/900000000000) asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1033 |
(500000000001/900000000000) asQuadFloat = (5/9) asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1034 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1035 |
(500000000000/9) asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1036 |
(5/900000000000) asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1037 |
89012345678901234567 asFloat / 123456789123456789 asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1038 |
(89012345678901234567 / 123456789123456789) asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1039 |
(-89012345678901234567 / 123456789123456789) asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1040 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1041 |
( |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1042 |
180338700661043257034670206806167960222709397862806840937993331366591676308781197477183367018067356365812757479444845320188679437752013593674158587947149815441890236037219685250845721864713487208757788709113534916165172927384095182655935222723385253851776639985379367854545495930551624041981995105743408203125 |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1043 |
/ |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1044 |
180331613628627651967947866455016278082980736719853750685591387625058011528928110602436691256100991596843001549483950600930062886280582766771424470965440873615557144641435276844465734361353086032476712374317224249252177316815544331763696909434844464464323192083930469387098582956241443753242492675781250 |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1045 |
) asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1046 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1047 |
180338700661043257034670206806167960222709397862806840937993331366591676308781197477183367018067356365812757479444845320188679437752013593674158587947149815441890236037219685250845721864713487208757788709113534916165172927384095182655935222723385253851776639985379367854545495930551624041981995105743408203125 |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1048 |
asQuadFloat / |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1049 |
180331613628627651967947866455016278082980736719853750685591387625058011528928110602436691256100991596843001549483950600930062886280582766771424470965440873615557144641435276844465734361353086032476712374317224249252177316815544331763696909434844464464323192083930469387098582956241443753242492675781250 |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1050 |
asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1051 |
" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1052 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1053 |
"Created: / 07-06-2019 / 02:32:19 / Claus Gittinger" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1054 |
! ! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1055 |
|
4383 | 1056 |
!Integer methodsFor:'coercing & converting'! |
1057 |
||
5354 | 1058 |
asIEEEFloat |
1059 |
"return an IEEEFloat with same value as the receiver" |
|
1060 |
||
1061 |
^ IEEEFloat fromInteger:self |
|
1062 |
||
1063 |
" |
|
1064 |
1234567890 asIEEEFloat |
|
1065 |
1234567890 asIEEEFloat asInteger |
|
1066 |
12345678901234567890 asIEEEFloat |
|
1067 |
12345678901234567890 asIEEEFloat asInteger |
|
1068 |
" |
|
1069 |
||
1070 |
||
1071 |
! ! |
|
1072 |
||
1073 |
!Integer methodsFor:'coercing & converting'! |
|
1074 |
||
5292
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1075 |
asOctaFloat |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1076 |
"return a OctaFloat with same value as myself. |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1077 |
Since octaFloats have a limited precision, you may loose bits when |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1078 |
doing this." |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1079 |
|
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1080 |
^ OctaFloat fromInteger:self |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1081 |
|
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1082 |
" |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1083 |
1234567890 asOctaFloat |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1084 |
1234567890 asOctaFloat asInteger |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1085 |
12345678901234567890 asOctaFloat |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1086 |
12345678901234567890 asOctaFloat asInteger |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1087 |
" |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1088 |
|
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1089 |
"Created: / 07-06-2019 / 02:30:38 / Claus Gittinger" |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1090 |
! ! |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1091 |
|
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1092 |
!Integer methodsFor:'coercing & converting'! |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1093 |
|
4383 | 1094 |
asQDouble |
1095 |
"return a QDouble with same value as myself." |
|
1096 |
||
1097 |
^ QDouble fromInteger:self |
|
1098 |
||
1099 |
" |
|
1100 |
1234567890 asQDouble |
|
1101 |
1234567890 asQDouble asInteger |
|
1102 |
12345678901234567890 asQDouble |
|
1103 |
12345678901234567890 asQDouble asInteger |
|
1104 |
" |
|
1105 |
||
1106 |
"Created: / 12-06-2017 / 18:41:07 / cg" |
|
1107 |
"Modified (comment): / 12-06-2017 / 20:55:24 / cg" |
|
1108 |
! ! |
|
1109 |
||
5292
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1110 |
!Integer methodsFor:'coercing & converting'! |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1111 |
|
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1112 |
asQuadFloat |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1113 |
"return a QuadFloat with same value as myself. |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1114 |
Since quadFloats have a limited precision, you may loose bits when |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1115 |
doing this." |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1116 |
|
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1117 |
^ QuadFloat fromInteger:self |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1118 |
|
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1119 |
" |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1120 |
1234567890 asQuadFloat |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1121 |
1234567890 asQuadFloat asInteger |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1122 |
12345678901234567890 asQuadFloat |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1123 |
12345678901234567890 asQuadFloat asInteger |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1124 |
" |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1125 |
|
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1126 |
"Created: / 07-06-2019 / 02:30:38 / Claus Gittinger" |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1127 |
! ! |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1128 |
|
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1129 |
!Integer methodsFor:'Compatibility-Squeak'! |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1130 |
|
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1131 |
atRandom |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1132 |
"return a random number between 1 and myself" |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1133 |
|
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1134 |
^ self atRandom:Random. |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1135 |
|
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1136 |
" |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1137 |
100 atRandom |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1138 |
1000 atRandom |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1139 |
" |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1140 |
! ! |
975a4c7373cb
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5234
diff
changeset
|
1141 |
|
5293
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1142 |
!LimitedPrecisionReal methodsFor:'coercing & converting'! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1143 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1144 |
asOctaFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1145 |
^ OctaFloat fromLimitedPrecisionReal:self |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1146 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1147 |
"Created: / 07-06-2019 / 02:30:07 / Claus Gittinger" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1148 |
! ! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1149 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1150 |
!LimitedPrecisionReal methodsFor:'coercing & converting'! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1151 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1152 |
asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1153 |
^ QuadFloat fromLimitedPrecisionReal:self |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1154 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1155 |
"Created: / 07-06-2019 / 02:30:07 / Claus Gittinger" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1156 |
! ! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1157 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1158 |
!LongFloat methodsFor:'coercing & converting'! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1159 |
|
5325 | 1160 |
asIEEEFloat |
1161 |
"return an IEEE soft float with same value as receiver" |
|
1162 |
||
1163 |
^ IEEEFloat fromFloat:self |
|
1164 |
||
1165 |
" |
|
1166 |
123 asFloat asIEEEFloat |
|
1167 |
0 asShortFloat asIEEEFloat |
|
1168 |
0 asLongFloat asIEEEFloat |
|
1169 |
0.0 asIEEEFloat |
|
1170 |
" |
|
1171 |
! ! |
|
1172 |
||
1173 |
!LongFloat methodsFor:'coercing & converting'! |
|
1174 |
||
5316
110397aa2b10
class: RegressionTests::QDoubleTests
Claus Gittinger <cg@exept.de>
parents:
5296
diff
changeset
|
1175 |
asQDouble |
110397aa2b10
class: RegressionTests::QDoubleTests
Claus Gittinger <cg@exept.de>
parents:
5296
diff
changeset
|
1176 |
"return a QDouble with my value" |
110397aa2b10
class: RegressionTests::QDoubleTests
Claus Gittinger <cg@exept.de>
parents:
5296
diff
changeset
|
1177 |
|
110397aa2b10
class: RegressionTests::QDoubleTests
Claus Gittinger <cg@exept.de>
parents:
5296
diff
changeset
|
1178 |
^ QDouble fromLongFloat:self |
110397aa2b10
class: RegressionTests::QDoubleTests
Claus Gittinger <cg@exept.de>
parents:
5296
diff
changeset
|
1179 |
|
110397aa2b10
class: RegressionTests::QDoubleTests
Claus Gittinger <cg@exept.de>
parents:
5296
diff
changeset
|
1180 |
" |
110397aa2b10
class: RegressionTests::QDoubleTests
Claus Gittinger <cg@exept.de>
parents:
5296
diff
changeset
|
1181 |
1.0 asLongFloat asQDouble |
110397aa2b10
class: RegressionTests::QDoubleTests
Claus Gittinger <cg@exept.de>
parents:
5296
diff
changeset
|
1182 |
" |
110397aa2b10
class: RegressionTests::QDoubleTests
Claus Gittinger <cg@exept.de>
parents:
5296
diff
changeset
|
1183 |
! ! |
110397aa2b10
class: RegressionTests::QDoubleTests
Claus Gittinger <cg@exept.de>
parents:
5296
diff
changeset
|
1184 |
|
110397aa2b10
class: RegressionTests::QDoubleTests
Claus Gittinger <cg@exept.de>
parents:
5296
diff
changeset
|
1185 |
!LongFloat methodsFor:'coercing & converting'! |
110397aa2b10
class: RegressionTests::QDoubleTests
Claus Gittinger <cg@exept.de>
parents:
5296
diff
changeset
|
1186 |
|
5293
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1187 |
asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1188 |
"return a QuadFloat with same value as the receiver" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1189 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1190 |
^ QuadFloat fromLongFloat:self |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1191 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1192 |
"Created: / 07-06-2019 / 02:46:30 / Claus Gittinger" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1193 |
! ! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1194 |
|
5296 | 1195 |
!MetaNumber methodsFor:'coercing & converting'! |
1196 |
||
1197 |
asOctaFloat |
|
1198 |
"return an OctaFloat with same value as the receiver. |
|
1199 |
For anything but NaN, +Inf or -Inf, an error is raised here." |
|
1200 |
||
1201 |
^ self asInstanceOf:OctaFloat fromSelector:#asOctaFloat |
|
1202 |
||
1203 |
" |
|
1204 |
Infinity NaN asFloat |
|
1205 |
Infinity NaN asOctaFloat |
|
1206 |
||
1207 |
Infinity positive asFloat |
|
1208 |
Infinity positive asOctaFloat |
|
1209 |
||
1210 |
Infinity negative asFloat |
|
1211 |
Infinity negative asOctaFloat |
|
1212 |
" |
|
1213 |
||
1214 |
"Created: / 21-06-2017 / 20:42:09 / cg" |
|
1215 |
! ! |
|
1216 |
||
1217 |
!MetaNumber methodsFor:'coercing & converting'! |
|
1218 |
||
1219 |
asQDouble |
|
1220 |
"return a QDouble with same value as the receiver. |
|
1221 |
For anything but NaN, +Inf or -Inf, an error is raised here." |
|
1222 |
||
1223 |
^ self asInstanceOf:QDouble fromSelector:#asQDouble |
|
1224 |
||
1225 |
" |
|
1226 |
Infinity NaN asFloat |
|
1227 |
Infinity NaN asQDouble |
|
1228 |
||
1229 |
Infinity positive asFloat |
|
1230 |
Infinity positive asQDouble |
|
1231 |
||
1232 |
Infinity negative asFloat |
|
1233 |
Infinity negative asQDouble |
|
1234 |
" |
|
1235 |
||
1236 |
"Created: / 21-06-2017 / 20:42:09 / cg" |
|
1237 |
! ! |
|
1238 |
||
1239 |
!MetaNumber methodsFor:'coercing & converting'! |
|
1240 |
||
1241 |
asQuadFloat |
|
1242 |
"return a QuadFloat with same value as the receiver. |
|
1243 |
For anything but NaN, +Inf or -Inf, an error is raised here." |
|
1244 |
||
1245 |
^ self asInstanceOf:QuadFloat fromSelector:#asQuadFloat |
|
1246 |
||
1247 |
" |
|
1248 |
Infinity NaN asFloat |
|
1249 |
Infinity NaN asQuadFloat |
|
1250 |
||
1251 |
Infinity positive asFloat |
|
1252 |
Infinity positive asQuadFloat |
|
1253 |
||
1254 |
Infinity negative asFloat |
|
1255 |
Infinity negative asQuadFloat |
|
1256 |
" |
|
1257 |
||
1258 |
"Created: / 21-06-2017 / 20:42:09 / cg" |
|
1259 |
! ! |
|
1260 |
||
1759 | 1261 |
!Object methodsFor:'dependents-interests'! |
1262 |
||
1263 |
addInterest:anInterest |
|
1264 |
"install an interest forwarder. |
|
1265 |
Here, we use the nonWeakDependencies." |
|
1266 |
||
1267 |
self addNonWeakDependent:anInterest |
|
1268 |
||
1269 |
"Created: 14.10.1996 / 22:27:34 / stefan" |
|
1270 |
! ! |
|
1271 |
||
3896 | 1272 |
!Object methodsFor:'converting'! |
1273 |
||
1274 |
asDoubleLink |
|
1275 |
"return a valueDoubleLink for the receiver. |
|
1276 |
Used to make sure the receiver can be added to a double linked list" |
|
1277 |
||
1278 |
^ ValueDoubleLink value:self |
|
1279 |
! ! |
|
1280 |
||
1759 | 1281 |
!Object methodsFor:'dependents-interests'! |
1282 |
||
1283 |
expressInterestIn:aspect for:anObject sendBack:aSelector |
|
1284 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
1285 |
changes aspect." |
|
1286 |
||
1287 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
1288 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1289 |
||
2303 | 1290 |
self addInterest:(InterestConverter |
1291 |
destination:anObject |
|
1292 |
selector:aSelector |
|
1293 |
aspect:aspect) |
|
1759 | 1294 |
|
1295 |
" |
|
1296 |
|p b| |
|
1297 |
||
1298 |
b := [Transcript showCR:' -> the point changed']. |
|
1299 |
||
1300 |
p := Point new. |
|
1301 |
Transcript showCR:'interest in #foo:'. |
|
1302 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
1303 |
p x:1. |
|
1304 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
1305 |
p changed:#bar. |
|
1306 |
Transcript cr. |
|
1307 |
||
1308 |
Delay waitForSeconds:1. |
|
1309 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
1310 |
p changed:#foo. |
|
1311 |
Transcript cr. |
|
1312 |
||
1313 |
Delay waitForSeconds:1. |
|
1314 |
Transcript showCR:'no more interest in #foo:'. |
|
1315 |
p retractInterestIn:#foo for:b. |
|
1316 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
1317 |
p changed:#foo. |
|
1318 |
Transcript cr. |
|
1319 |
||
1320 |
Delay waitForSeconds:1. |
|
1321 |
Transcript showCR:'interest in #bar now:'. |
|
1322 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
1323 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
1324 |
p changed:#foo. |
|
1325 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
1326 |
p changed:#bar. |
|
1327 |
Transcript cr. |
|
1328 |
||
1329 |
Delay waitForSeconds:1. |
|
1330 |
Transcript showCR:'interest in #foo now:'. |
|
1331 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
1332 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
1333 |
p changed:#foo. |
|
1334 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
1335 |
p changed:#bar. |
|
1336 |
Transcript cr. |
|
1337 |
||
1338 |
Delay waitForSeconds:1. |
|
1339 |
Transcript showCR:'no more interests:'. |
|
1340 |
p retractInterestsFor:b. |
|
1341 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
1342 |
p changed:#foo. |
|
1343 |
Transcript showCR:'now changing #bar... (expect no notification)'. |
|
1344 |
p changed:#bar. |
|
1345 |
Transcript cr. |
|
1346 |
||
1347 |
p release. |
|
1348 |
" |
|
1668 | 1349 |
|
1759 | 1350 |
"Created: 19.4.1996 / 10:26:22 / cg" |
1351 |
"Modified: 19.4.1996 / 12:34:08 / cg" |
|
1352 |
"Modified: 14.10.1996 / 22:28:20 / stefan" |
|
1353 |
! ! |
|
1354 |
||
1355 |
!Object methodsFor:'dependents-interests'! |
|
1356 |
||
1357 |
interests |
|
1358 |
"return a Collection of interests - empty if there is none. |
|
1359 |
Here, we use the nonWeakDependents for interests." |
|
1360 |
||
1361 |
^ self nonWeakDependents |
|
1362 |
||
1363 |
"Created: / 14.10.1996 / 22:20:51 / stefan" |
|
1364 |
"Modified: / 30.1.1998 / 14:07:35 / cg" |
|
1365 |
! ! |
|
1366 |
||
1367 |
!Object methodsFor:'dependents-interests'! |
|
1368 |
||
1369 |
interestsFor:someOne |
|
1370 |
"return a collection of interests of someOne - empty if there is none." |
|
1371 |
||
1372 |
|coll deps| |
|
1373 |
||
1374 |
deps := self interests. |
|
1375 |
deps size == 0 ifTrue:[^ #()]. |
|
1376 |
||
1377 |
coll := IdentitySet new. |
|
1378 |
||
1379 |
deps do:[:dep | |
|
2303 | 1380 |
(dep isInterestConverter) ifTrue:[ |
1381 |
dep destination == someOne ifTrue:[ |
|
1382 |
coll add:dep. |
|
1383 |
] |
|
1384 |
] |
|
1759 | 1385 |
]. |
1386 |
^ coll |
|
1387 |
||
1388 |
"Created: / 30.1.1998 / 14:02:26 / cg" |
|
1389 |
"Modified: / 30.1.1998 / 14:08:24 / cg" |
|
1390 |
! ! |
|
1668 | 1391 |
|
1759 | 1392 |
!Object methodsFor:'dependents-interests'! |
1393 |
||
5139 | 1394 |
onChange:aspect evaluate:aBlock |
1395 |
"arrange for aBlock to be evaluated whenever the receiver changes the given aspect." |
|
1396 |
||
1397 |
|na selector| |
|
1398 |
||
1399 |
na := aBlock argumentCount. |
|
1400 |
na == 0 ifTrue:[ |
|
1401 |
selector := #value |
|
1402 |
] ifFalse:[ |
|
1403 |
selector := #( #'value:' #'value:value:' #'value:value:value:') at:na |
|
1404 |
]. |
|
1405 |
^ self onChange:aspect send:selector to:aBlock |
|
1406 |
||
1407 |
" |
|
1408 |
|p b| |
|
1409 |
||
1410 |
b := [Transcript showCR:' -> the point changed X']. |
|
1411 |
||
1412 |
p := Point new. |
|
1413 |
Transcript showCR:'interest in #x, #y'. |
|
1414 |
p onChange:#x evaluate:b. |
|
1415 |
p onChange:#y evaluate:[Transcript showCR:' -> the point changed Y']. |
|
1416 |
Transcript showCR:'now changing ...'. |
|
1417 |
p changed. |
|
1418 |
Transcript showCR:'now changing #bar ...'. |
|
1419 |
p changed:#bar. |
|
1420 |
Transcript showCR:'now changing #x ...'. |
|
1421 |
p x:1. |
|
1422 |
p changed:#x. |
|
1423 |
Transcript showCR:'now changing #y ...'. |
|
1424 |
p y:1. |
|
1425 |
p changed:#y. |
|
1426 |
||
1427 |
Transcript showCR:'no more interests'. |
|
1428 |
p retractInterests. |
|
1429 |
p changed:#bar. |
|
1430 |
p changed:#y. |
|
1431 |
p changed:#x. |
|
1432 |
" |
|
1433 |
! ! |
|
1434 |
||
1435 |
!Object methodsFor:'dependents-interests'! |
|
1436 |
||
1437 |
onChange:aspect send:aSelector to:anObject |
|
1438 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
1439 |
changed the given aspect. |
|
1440 |
Use retractInterestsFor: in case you are no longer interested" |
|
1441 |
||
1442 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
1443 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1444 |
||
1445 |
(self interests contains:[:anInterest | |
|
1446 |
anInterest isInterestConverter |
|
1447 |
and:[anInterest destination == anObject |
|
1448 |
and:[anInterest selector == aSelector |
|
1449 |
and:[anInterest aspect == aspect]]] |
|
1450 |
] |
|
1451 |
) ifFalse:[ |
|
1452 |
self addInterest:(InterestConverter |
|
1453 |
destination:anObject |
|
1454 |
selector:aSelector |
|
1455 |
aspect:aspect) |
|
1456 |
]. |
|
1457 |
||
1458 |
||
1459 |
" |
|
1460 |
|p b| |
|
1461 |
||
1462 |
b := [Transcript showCR:'the point changed X']. |
|
1463 |
||
1464 |
p := Point new. |
|
1465 |
p onChange:#x send:#value to:b. |
|
1466 |
p onChange:#y send:#value to:[Transcript showCR:'the point changed Y']. |
|
1467 |
Transcript showCR:'now changing x'. |
|
1468 |
p x:1. |
|
1469 |
p changed:#x. |
|
1470 |
Transcript cr. |
|
1471 |
||
1472 |
Transcript showCR:'now changing y'. |
|
1473 |
p y:2. |
|
1474 |
p changed:#y. |
|
1475 |
Transcript cr. |
|
1476 |
||
1477 |
Delay waitForSeconds:1. |
|
1478 |
Transcript showCR:'now changing (any)'. |
|
1479 |
p changed. |
|
1480 |
Transcript cr. |
|
1481 |
||
1482 |
Delay waitForSeconds:1. |
|
1483 |
Transcript showCR:'no more interest in x'. |
|
1484 |
p retractInterestsFor:b. |
|
1485 |
Transcript showCR:'now changing again'. |
|
1486 |
p changed:#y. |
|
1487 |
p changed:#x. |
|
1488 |
p changed. |
|
1489 |
Transcript cr. |
|
1490 |
||
1491 |
Delay waitForSeconds:1. |
|
1492 |
Transcript showCR:'interest in x again'. |
|
1493 |
p onChange:#x send:#value to:b. |
|
1494 |
Transcript showCR:'now changing again'. |
|
1495 |
p changed:#y. |
|
1496 |
p changed:#x. |
|
1497 |
p changed. |
|
1498 |
Transcript cr. |
|
1499 |
||
1500 |
Transcript showCR:'no more interest at all'. |
|
1501 |
p retractInterests. |
|
1502 |
p changed:#y. |
|
1503 |
p changed:#x. |
|
1504 |
p changed. |
|
1505 |
Transcript cr. |
|
1506 |
" |
|
1507 |
||
1508 |
"Created: / 19-04-1996 / 10:26:38 / cg" |
|
1509 |
"Modified: / 19-04-1996 / 12:34:26 / cg" |
|
1510 |
"Modified: / 14-10-1996 / 22:28:27 / stefan" |
|
1511 |
"Modified: / 30-11-2018 / 18:01:47 / Stefan Vogel" |
|
1512 |
! ! |
|
1513 |
||
1514 |
!Object methodsFor:'dependents-interests'! |
|
1515 |
||
1759 | 1516 |
onChangeEvaluate:aBlock |
1517 |
"arrange for aBlock to be evaluated whenever the receiver changes." |
|
1518 |
||
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
|
1519 |
|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
|
1520 |
|
3559
fa3443d808a1
Changed Object>>#onChangeEvaluate: (send #argumentCount instead of #numArgs)
Stefan Vogel <sv@exept.de>
parents:
3538
diff
changeset
|
1521 |
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
|
1522 |
na == 0 ifTrue:[ |
3559
fa3443d808a1
Changed Object>>#onChangeEvaluate: (send #argumentCount instead of #numArgs)
Stefan Vogel <sv@exept.de>
parents:
3538
diff
changeset
|
1523 |
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
|
1524 |
] ifFalse:[ |
3559
fa3443d808a1
Changed Object>>#onChangeEvaluate: (send #argumentCount instead of #numArgs)
Stefan Vogel <sv@exept.de>
parents:
3538
diff
changeset
|
1525 |
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
|
1526 |
]. |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
1527 |
^ self onChangeSend:selector to:aBlock |
1759 | 1528 |
|
1529 |
" |
|
1530 |
|p b| |
|
1531 |
||
1532 |
b := [Transcript showCR:' -> the point changed']. |
|
1533 |
||
1534 |
p := Point new. |
|
1535 |
Transcript showCR:'interest in #foo:'. |
|
1536 |
p onChangeEvaluate:b. |
|
1537 |
p x:1. |
|
1538 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
1539 |
p changed:#bar. |
|
1540 |
||
1541 |
p retractInterests. |
|
1542 |
p changed:#bar. |
|
1543 |
" |
|
1544 |
! ! |
|
1545 |
||
1546 |
!Object methodsFor:'dependents-interests'! |
|
1547 |
||
1548 |
onChangeSend:aSelector to:anObject |
|
1549 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
4030 | 1550 |
changes. |
1551 |
Use retractInterestsFor: in case you are no longer interested" |
|
1759 | 1552 |
|
1553 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
1554 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1555 |
||
4773 | 1556 |
(self interests contains:[:anInterest | |
1557 |
anInterest isInterestConverter |
|
1558 |
and:[anInterest destination == anObject |
|
1559 |
and:[anInterest selector == aSelector]] |
|
1560 |
] |
|
1561 |
) ifFalse:[ |
|
1562 |
self addInterest:(InterestConverter |
|
1563 |
destination:anObject |
|
1564 |
selector:aSelector) |
|
1565 |
]. |
|
1759 | 1566 |
|
1668 | 1567 |
|
1568 |
" |
|
1759 | 1569 |
|p b| |
1570 |
||
1571 |
b := [Transcript showCR:'the point changed']. |
|
1572 |
||
1573 |
p := Point new. |
|
1574 |
p onChangeSend:#value to:b. |
|
1575 |
p x:1. |
|
1576 |
Transcript showCR:'now changing'. |
|
1577 |
p changed. |
|
1578 |
Transcript cr. |
|
1579 |
||
1580 |
Delay waitForSeconds:1. |
|
1581 |
Transcript showCR:'now changing'. |
|
1582 |
p changed. |
|
1583 |
Transcript cr. |
|
1584 |
||
1585 |
Delay waitForSeconds:1. |
|
1586 |
Transcript showCR:'no more interest'. |
|
1587 |
p retractInterestsFor:b. |
|
1588 |
Transcript showCR:'now changing again'. |
|
1589 |
p changed. |
|
1590 |
Transcript cr. |
|
1591 |
||
1592 |
Delay waitForSeconds:1. |
|
1593 |
Transcript showCR:'interest again'. |
|
1594 |
p onChangeSend:#value to:b. |
|
1595 |
Transcript showCR:'now changing again'. |
|
1596 |
p changed. |
|
1597 |
Transcript cr. |
|
1598 |
" |
|
1599 |
||
4773 | 1600 |
"Created: / 19-04-1996 / 10:26:38 / cg" |
1601 |
"Modified: / 19-04-1996 / 12:34:26 / cg" |
|
1602 |
"Modified: / 14-10-1996 / 22:28:27 / stefan" |
|
1603 |
"Modified: / 30-11-2018 / 18:01:47 / Stefan Vogel" |
|
1759 | 1604 |
! ! |
1605 |
||
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1606 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1607 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1608 |
removeActionsForEvent:eventSymbol |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1609 |
"remove ST/V-style event triggers." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1610 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1611 |
self retractInterestsIn:eventSymbol |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1612 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1613 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1614 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1615 |
|
2903 | 1616 |
removeActionsWithReceiver:aReceiver |
1617 |
"remove ST/V-style event triggers." |
|
1618 |
||
1619 |
self retractInterestsFor:aReceiver |
|
1620 |
! ! |
|
1621 |
||
1622 |
!Object methodsFor:'dependents-st/v event simulation'! |
|
1623 |
||
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1624 |
removeAllActionsWithReceiver:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1625 |
"remove ST/V-style event triggers." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1626 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1627 |
self retractInterestsFor:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1628 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1629 |
|
1759 | 1630 |
!Object methodsFor:'dependents-interests'! |
1631 |
||
4969
9acd20c528a3
combination retract+removeDependent
Claus Gittinger <cg@exept.de>
parents:
4866
diff
changeset
|
1632 |
removeDependentAndRetractInterestsFor:someOne |
9acd20c528a3
combination retract+removeDependent
Claus Gittinger <cg@exept.de>
parents:
4866
diff
changeset
|
1633 |
"remove any dependency and interest of someOne in the receiver. |
9acd20c528a3
combination retract+removeDependent
Claus Gittinger <cg@exept.de>
parents:
4866
diff
changeset
|
1634 |
Answer the receiver" |
9acd20c528a3
combination retract+removeDependent
Claus Gittinger <cg@exept.de>
parents:
4866
diff
changeset
|
1635 |
|
9acd20c528a3
combination retract+removeDependent
Claus Gittinger <cg@exept.de>
parents:
4866
diff
changeset
|
1636 |
self retractInterestsFor:someOne. |
9acd20c528a3
combination retract+removeDependent
Claus Gittinger <cg@exept.de>
parents:
4866
diff
changeset
|
1637 |
self removeDependent:someOne. |
9acd20c528a3
combination retract+removeDependent
Claus Gittinger <cg@exept.de>
parents:
4866
diff
changeset
|
1638 |
|
9acd20c528a3
combination retract+removeDependent
Claus Gittinger <cg@exept.de>
parents:
4866
diff
changeset
|
1639 |
"Created: / 30-05-2019 / 11:11:19 / Claus Gittinger" |
9acd20c528a3
combination retract+removeDependent
Claus Gittinger <cg@exept.de>
parents:
4866
diff
changeset
|
1640 |
! ! |
9acd20c528a3
combination retract+removeDependent
Claus Gittinger <cg@exept.de>
parents:
4866
diff
changeset
|
1641 |
|
9acd20c528a3
combination retract+removeDependent
Claus Gittinger <cg@exept.de>
parents:
4866
diff
changeset
|
1642 |
!Object methodsFor:'dependents-interests'! |
9acd20c528a3
combination retract+removeDependent
Claus Gittinger <cg@exept.de>
parents:
4866
diff
changeset
|
1643 |
|
1759 | 1644 |
removeInterest:anInterest |
1645 |
"remove an interest forwarder. |
|
1646 |
Here, we use the nonWeakDependencies." |
|
1647 |
||
1648 |
self removeNonWeakDependent:anInterest |
|
1649 |
||
1650 |
"Created: 14.10.1996 / 22:21:59 / stefan" |
|
1651 |
! ! |
|
1652 |
||
1653 |
!Object methodsFor:'dependents-interests'! |
|
1654 |
||
1655 |
retractInterestIn:aspect for:someOne |
|
1656 |
"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
|
1657 |
(as installed with #expressInterestIn:for:sendBack:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1658 |
Answer the retracted interests." |
1759 | 1659 |
|
1660 |
"/ for now, remove the interestConverter. |
|
1661 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1662 |
||
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1663 |
^ self retractInterestsForWhich:[:i | |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1664 |
(i aspect == aspect) and:[i destination == someOne] |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1665 |
] |
1759 | 1666 |
|
1668 | 1667 |
" |
1759 | 1668 |
|p b| |
1669 |
||
1670 |
b := [Transcript showCR:'the point changed']. |
|
1671 |
||
1672 |
p := Point new. |
|
1673 |
Transcript showCR:'interest in #foo'. |
|
1674 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
1675 |
p x:1. |
|
1676 |
Transcript showCR:'now changing #bar'. |
|
1677 |
p changed:#bar. |
|
1678 |
Transcript cr. |
|
1679 |
||
1680 |
Delay waitForSeconds:1. |
|
1681 |
Transcript showCR:'now changing #foo'. |
|
1682 |
p changed:#foo. |
|
1683 |
Transcript cr. |
|
1684 |
||
1685 |
Delay waitForSeconds:1. |
|
1686 |
Transcript showCR:'no more interest in #foo'. |
|
1687 |
p retractInterestIn:#foo for:b. |
|
1688 |
Transcript showCR:'now changing #foo'. |
|
1689 |
p changed:#foo. |
|
1690 |
Transcript cr. |
|
1691 |
||
1692 |
Delay waitForSeconds:1. |
|
1693 |
Transcript showCR:'interest in #bar now'. |
|
1694 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
1695 |
Transcript showCR:'now changing #foo'. |
|
1696 |
p changed:#foo. |
|
1697 |
Transcript showCR:'now changing #bar'. |
|
1698 |
p changed:#bar. |
|
1699 |
Transcript cr. |
|
1700 |
||
1701 |
Delay waitForSeconds:1. |
|
1702 |
Transcript showCR:'interest in #foo now'. |
|
1703 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
1704 |
Transcript showCR:'now changing #foo'. |
|
1705 |
p changed:#foo. |
|
1706 |
Transcript showCR:'now changing #bar'. |
|
1707 |
p changed:#bar. |
|
1708 |
Transcript cr. |
|
1709 |
||
1710 |
Delay waitForSeconds:1. |
|
1711 |
Transcript showCR:'no more interests'. |
|
1712 |
p retractInterestsFor:b. |
|
1713 |
Transcript showCR:'now changing #foo'. |
|
1714 |
p changed:#foo. |
|
1715 |
Transcript showCR:'now changing #bar'. |
|
1716 |
p changed:#bar. |
|
1717 |
Transcript cr. |
|
1718 |
" |
|
1719 |
||
1720 |
"Created: / 19.4.1996 / 10:27:11 / cg" |
|
1721 |
"Modified: / 14.10.1996 / 22:21:19 / stefan" |
|
1722 |
"Modified: / 30.1.1998 / 14:05:34 / cg" |
|
1723 |
! ! |
|
1724 |
||
1725 |
!Object methodsFor:'dependents-interests'! |
|
1726 |
||
1727 |
retractInterests |
|
1728 |
"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
|
1729 |
(as installed with #expressInterestIn:for:sendBack:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1730 |
Answer the retraced interests." |
1759 | 1731 |
|
1732 |
"/ for now, remove the interestConverter. |
|
1733 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1734 |
||
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1735 |
^ self retractInterestsForWhich:[:i | true ] |
1759 | 1736 |
! ! |
1737 |
||
1738 |
!Object methodsFor:'dependents-interests'! |
|
1739 |
||
1740 |
retractInterestsFor:someOne |
|
2303 | 1741 |
"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
|
1742 |
(as installed with #onChangeSend:to:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1743 |
Answer the retracted interests." |
1759 | 1744 |
|
1745 |
"/ for now, remove the interestConverter. |
|
1746 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1747 |
||
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1748 |
^ self retractInterestsForWhich:[:i | i destination == someOne ] |
1759 | 1749 |
|
1750 |
" |
|
1751 |
|p b| |
|
1752 |
||
1753 |
b := [Transcript showCR:'the point changed']. |
|
1754 |
||
1755 |
p := Point new. |
|
1756 |
p onChangeSend:#value to:b. |
|
1757 |
p x:1. |
|
1758 |
Transcript showCR:'now changing'. |
|
1759 |
p changed. |
|
1760 |
Transcript cr. |
|
1761 |
||
1762 |
Delay waitForSeconds:1. |
|
1763 |
Transcript showCR:'now changing'. |
|
1764 |
p changed. |
|
1765 |
Transcript cr. |
|
1766 |
||
1767 |
Delay waitForSeconds:1. |
|
1768 |
Transcript showCR:'no more interest'. |
|
1769 |
p retractInterestsFor:b. |
|
1770 |
Transcript showCR:'now changing again'. |
|
1771 |
p changed. |
|
1772 |
Transcript cr. |
|
1773 |
||
1774 |
Delay waitForSeconds:1. |
|
1775 |
Transcript showCR:'interest again'. |
|
1776 |
p onChangeSend:#value to:b. |
|
1777 |
Transcript showCR:'now changing again'. |
|
1778 |
p changed. |
|
1779 |
Transcript cr. |
|
1780 |
" |
|
1781 |
||
1782 |
"Created: / 19.4.1996 / 10:23:46 / cg" |
|
1783 |
"Modified: / 14.10.1996 / 22:21:25 / stefan" |
|
1784 |
"Modified: / 30.1.1998 / 14:04:52 / cg" |
|
1785 |
! ! |
|
1786 |
||
1787 |
!Object methodsFor:'dependents-interests'! |
|
1788 |
||
1789 |
retractInterestsForWhich:aBlock |
|
1790 |
"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
|
1791 |
(as installed with #expressInterestIn:for:sendBack:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1792 |
Answer the retracted interests." |
1759 | 1793 |
|
1794 |
"/ for now, remove the interestConverter. |
|
1795 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1796 |
||
5139 | 1797 |
|deps toRemove| |
1759 | 1798 |
|
1799 |
deps := self interests. |
|
1800 |
deps size ~~ 0 ifTrue:[ |
|
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1801 |
"/ cannot removeDependent within the loop - the interests collection rehashes |
5139 | 1802 |
toRemove := IdentitySet new. |
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1803 |
deps do:[:dep | |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1804 |
dep isInterestConverter ifTrue:[ |
5139 | 1805 |
(aBlock value:dep) ifTrue:[toRemove add:dep]. |
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1806 |
] |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1807 |
]. |
5139 | 1808 |
toRemove do:[:dep | |
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1809 |
self removeInterest:dep. |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1810 |
]. |
5139 | 1811 |
^ toRemove. |
1759 | 1812 |
]. |
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1813 |
^ #() |
1759 | 1814 |
! ! |
1815 |
||
1816 |
!Object methodsFor:'dependents-interests'! |
|
1817 |
||
1818 |
retractInterestsIn:aspect |
|
1819 |
"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
|
1820 |
(as installed with #expressInterestIn:for:sendBack:). |
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1821 |
Answer the retracted interests." |
1759 | 1822 |
|
1823 |
"/ for now, remove the interestConverter. |
|
1824 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
1825 |
||
4202
88ea818849fa
change #retractInterest* to return the retracted interests
Stefan Vogel <sv@exept.de>
parents:
4190
diff
changeset
|
1826 |
^ self retractInterestsForWhich:[:i | i aspect == aspect ] |
1668 | 1827 |
! ! |
1828 |
||
2901 | 1829 |
!Object methodsFor:'Compatibility-Dolphin'! |
1830 |
||
1831 |
trigger:anAspect |
|
1832 |
self changed:anAspect |
|
1833 |
! ! |
|
1834 |
||
1835 |
!Object methodsFor:'Compatibility-Dolphin'! |
|
1836 |
||
1837 |
trigger:anAspect with:anArgument |
|
1838 |
self changed:anAspect with:anArgument |
|
1839 |
! ! |
|
1840 |
||
1841 |
!Object methodsFor:'dependents-st/v event simulation'! |
|
1842 |
||
1843 |
triggerEvent:aSymbol |
|
1844 |
self changed:aSymbol |
|
1845 |
! ! |
|
1846 |
||
1668 | 1847 |
!Object methodsFor:'dependents-st/v event simulation'! |
1848 |
||
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1849 |
triggerEvent:eventSymbol with:aParameter |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1850 |
"perform ST/V-style event triggering." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1851 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1852 |
self changed:eventSymbol with:(Array with:aParameter). |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1853 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1854 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1855 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1856 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1857 |
triggerEvent:eventSymbol withArguments:parameters |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1858 |
"perform ST/V-style event triggering." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1859 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1860 |
self changed:eventSymbol with:parameters. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1861 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1862 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1863 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1864 |
|
1668 | 1865 |
when:eventSymbol send:selector to:anObject |
1866 |
"install an ST/V-style interest forwarder. |
|
1867 |
Here, we use the nonWeakDependencies." |
|
1868 |
||
1869 |
self addInterest:(InterestConverterWithParameters |
|
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1870 |
destination:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1871 |
selector:selector |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1872 |
aspect:eventSymbol). |
1668 | 1873 |
|
1874 |
" |
|
1875 |
|p b| |
|
1876 |
||
1877 |
b := [Transcript showCR:'the point changed']. |
|
1878 |
||
1879 |
p := Point new. |
|
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1880 |
p when:#foo:bar: send:#value:value: to:[:a :b | Transcript show:'foo: '; show:a; show:' bar: '; showCR:b]. |
1668 | 1881 |
Transcript showCR:'now changing'. |
1882 |
p triggerEvent:#foo:bar: withArguments:#('fooArg' 'barArg'). |
|
2897
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1883 |
p removeActionsForEvent:#foo:bar:. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1884 |
" |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1885 |
! ! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1886 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1887 |
!Object methodsFor:'dependents-st/v event simulation'! |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1888 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1889 |
when:eventSymbol send:selector to:anObject with:aParameter |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1890 |
"install an ST/V-style interest forwarder. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1891 |
Here, we use the nonWeakDependencies." |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1892 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1893 |
self addInterest:((InterestConverterWithParameters |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1894 |
destination:anObject |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1895 |
selector:selector |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1896 |
aspect:eventSymbol) |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1897 |
defaultParameters:(Array with:aParameter)). |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1898 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1899 |
" |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1900 |
|p b| |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1901 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1902 |
b := [Transcript showCR:'the point changed']. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1903 |
|
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1904 |
p := Point new. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1905 |
p |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1906 |
when:#foo: |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1907 |
send:#value: |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1908 |
to:[:a | Transcript show:'foo: '; showCR:a] |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1909 |
with:123. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1910 |
Transcript showCR:'now changing'. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1911 |
p triggerEvent:#foo:. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1912 |
p triggerEvent:#foo: with:987. |
3060cf059978
more trigger event simulation stuff
Claus Gittinger <cg@exept.de>
parents:
2679
diff
changeset
|
1913 |
p removeActionsForEvent:#foo:. |
1668 | 1914 |
" |
1915 |
! ! |
|
1916 |
||
2901 | 1917 |
!Object methodsFor:'Compatibility-Dolphin'! |
1918 |
||
1919 |
when:anAspect sendTo:anObject |
|
1920 |
self expressInterestIn:anAspect for:anObject sendBack:anAspect |
|
1921 |
! ! |
|
1922 |
||
5293
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1923 |
!ShortFloat methodsFor:'coercing & converting'! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1924 |
|
5325 | 1925 |
asIEEEFloat |
1926 |
"return an IEEE soft float with same value as receiver" |
|
1927 |
||
1928 |
^ IEEEFloat fromFloat:self |
|
1929 |
||
1930 |
" |
|
1931 |
123 asFloat asIEEEFloat |
|
1932 |
0 asShortFloat asIEEEFloat |
|
1933 |
0 asLongFloat asIEEEFloat |
|
1934 |
0.0 asIEEEFloat |
|
1935 |
" |
|
1936 |
! ! |
|
1937 |
||
1938 |
!ShortFloat methodsFor:'coercing & converting'! |
|
1939 |
||
5293
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1940 |
asQuadFloat |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1941 |
"return a QuadFloat with same value as the receiver" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1942 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1943 |
^ QuadFloat fromShortFloat:self |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1944 |
|
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1945 |
"Created: / 07-06-2019 / 02:29:14 / Claus Gittinger" |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1946 |
! ! |
db346a540bf9
methods shuffled to their package
Claus Gittinger <cg@exept.de>
parents:
5292
diff
changeset
|
1947 |
|
2364 | 1948 |
!Stream methodsFor:'stacked computing streams'! |
1949 |
||
1950 |
collecting:aBlock |
|
1951 |
"return a stacked computing stream, which reads elements from the receiver, |
|
1952 |
applies aBlock to each read element, and provides the results as elements to its reader." |
|
1953 |
||
1954 |
^ CollectingReadStream on:self collecting:aBlock |
|
3094 | 1955 |
|
1956 |
" |
|
1957 |
|s s2| |
|
1958 |
||
1959 |
s := 'hello world' readStream. |
|
1960 |
s2 := s collecting:[:ch | ch asUppercase]. |
|
1961 |
s2 upToEnd. |
|
1962 |
" |
|
2364 | 1963 |
! ! |
1964 |
||
4620 | 1965 |
!Stream methodsFor:'writing'! |
1966 |
||
5455 | 1967 |
printf:formatString |
4620 | 1968 |
"C-style printing into a stream. |
1969 |
For smalltalk specific formats, |
|
1970 |
see documentation in PrintfScanf >> format_printf" |
|
1971 |
||
5455 | 1972 |
formatString printf:#() on:self. |
4620 | 1973 |
|
1974 |
" |
|
1975 |
Transcript printf:'Hello World\n' |
|
4866 | 1976 |
Transcript printf:'Hello World %d\n' with:123 |
4620 | 1977 |
" |
4866 | 1978 |
|
1979 |
"Modified (comment): / 17-03-2019 / 15:05:29 / Claus Gittinger" |
|
4620 | 1980 |
! ! |
1981 |
||
1982 |
!Stream methodsFor:'writing'! |
|
1983 |
||
5455 | 1984 |
printf:formatString arguments:arguments |
4620 | 1985 |
"C-style printing into a stream. |
1986 |
Same as printf:withAll:, for protocol completeness. |
|
1987 |
For smalltalk specific formats, |
|
1988 |
see documentation in PrintfScanf >> format_printf" |
|
1989 |
||
5455 | 1990 |
formatString printf:arguments on:self. |
4620 | 1991 |
|
1992 |
" |
|
1993 |
Transcript printf:'%05x %d %f %o\n' withAll:{ 123. 234*5. 1.234. 8r377 } |
|
1994 |
Transcript printf:'%03d %03d %03d\n' withAll:{ 1. 2. 3 } |
|
1995 |
" |
|
1996 |
||
1997 |
"Created: / 23-02-2017 / 16:43:39 / cg" |
|
1998 |
! ! |
|
1999 |
||
2000 |
!Stream methodsFor:'writing'! |
|
2001 |
||
5455 | 2002 |
printf:formatString with:argument |
4620 | 2003 |
"C-style printing into a stream. |
2004 |
For smalltalk specific formats, |
|
2005 |
see documentation in PrintfScanf >> format_printf" |
|
2006 |
||
5455 | 2007 |
formatString printf:{argument} on:self. |
4620 | 2008 |
|
2009 |
" |
|
2010 |
Transcript printf:'%05x\n' with:12345 |
|
2011 |
" |
|
2012 |
! ! |
|
2013 |
||
2014 |
!Stream methodsFor:'writing'! |
|
2015 |
||
5455 | 2016 |
printf:formatString with:argument1 with:argument2 |
4620 | 2017 |
"C-style printing into a stream. |
2018 |
For smalltalk specific formats, |
|
2019 |
see documentation in PrintfScanf >> format_printf" |
|
2020 |
||
5455 | 2021 |
formatString printf:{argument1 . argument2} on:self. |
4620 | 2022 |
|
2023 |
" |
|
2024 |
Transcript printf:'%05x %3s\n' with:12345 with:'abc' |
|
2025 |
" |
|
2026 |
! ! |
|
2027 |
||
2028 |
!Stream methodsFor:'writing'! |
|
2029 |
||
5455 | 2030 |
printf:formatString with:argument1 with:argument2 with:argument3 |
4620 | 2031 |
"C-style printing into a stream. |
2032 |
For smalltalk specific formats, |
|
2033 |
see documentation in PrintfScanf >> format_printf" |
|
2034 |
||
5455 | 2035 |
formatString printf:{argument1 . argument2 . argument3} on:self. |
4620 | 2036 |
|
2037 |
" |
|
2038 |
Transcript printf:'%05x %3s %09s\n' with:12345 with:'abc' with:'abc' |
|
2039 |
Transcript printf:'%05x %3s %9s\n' with:12345 with:'abc' with:'abc' |
|
2040 |
" |
|
2041 |
! ! |
|
2042 |
||
2043 |
!Stream methodsFor:'writing'! |
|
2044 |
||
5455 | 2045 |
printf:formatString with:argument1 with:argument2 with:argument3 with:argument4 |
4620 | 2046 |
"C-style printing into a stream. |
2047 |
For smalltalk specific formats, |
|
2048 |
see documentation in PrintfScanf >> format_printf" |
|
2049 |
||
5455 | 2050 |
formatString printf:{argument1 . argument2 . argument3 . argument4} on:self. |
4620 | 2051 |
|
2052 |
" |
|
2053 |
Transcript printf:'%02x %02x %02x %02x\n' with:1 with:2 with:3 with:4 |
|
2054 |
Transcript printf:'%2x %2x %2x %2x\n' with:1 with:2 with:3 with:4 |
|
2055 |
Transcript printf:'%-2x %-2x %-2x %-2x\n' with:1 with:2 with:3 with:4 |
|
2056 |
" |
|
2057 |
! ! |
|
2058 |
||
2059 |
!Stream methodsFor:'writing'! |
|
2060 |
||
5455 | 2061 |
printf:formatString with:argument1 with:argument2 with:argument3 with:argument4 with:argument5 |
4620 | 2062 |
"C-style printing into a stream. |
2063 |
For smalltalk specific formats, |
|
2064 |
see documentation in PrintfScanf >> format_printf" |
|
2065 |
||
5455 | 2066 |
formatString printf:{argument1 . argument2 . argument3 . argument4 . argument5} on:self. |
4620 | 2067 |
|
2068 |
" |
|
2069 |
Transcript printf:'%02x %02x %02x %02x\n' with:1 with:2 with:3 with:4 |
|
2070 |
Transcript printf:'%2x %2x %2x %2x\n' with:1 with:2 with:3 with:4 |
|
2071 |
Transcript printf:'%-2x %-2x %-2x %-2x\n' with:1 with:2 with:3 with:4 |
|
2072 |
" |
|
2073 |
! ! |
|
2074 |
||
2075 |
!Stream methodsFor:'writing'! |
|
2076 |
||
5455 | 2077 |
printf:formatString withAll:arguments |
4620 | 2078 |
"C-style printing into a stream. |
2079 |
For smalltalk specific formats, |
|
2080 |
see documentation in PrintfScanf >> format_printf" |
|
2081 |
||
5455 | 2082 |
formatString printf:arguments on:self. |
4620 | 2083 |
|
2084 |
" |
|
2085 |
Transcript printf:'%05x %d %f %o\n' withAll:{ 123. 234*5. 1.234. 8r377 } |
|
2086 |
Transcript printf:'%03d %03d %03d\n' withAll:{ 1. 2. 3 } |
|
2087 |
" |
|
2088 |
! ! |
|
2089 |
||
2364 | 2090 |
!Stream methodsFor:'stacked computing streams'! |
2091 |
||
2092 |
selecting:aBlock |
|
2093 |
"return a stacked computing stream, which reads elements from the receiver, |
|
2094 |
but only provides elements for which aBlock returns true to its reader." |
|
2095 |
||
2096 |
^ SelectingReadStream on:self selecting:aBlock |
|
3094 | 2097 |
|
2098 |
" |
|
2099 |
|s s2| |
|
2100 |
||
2101 |
s := 'hello world' readStream. |
|
2102 |
s2 := s selecting:[:ch | ch isVowel]. |
|
2103 |
s2 upToEnd. |
|
2104 |
" |
|
2364 | 2105 |
! ! |
2106 |
||
2303 | 2107 |
!stx_libbasic2 class methodsFor:'documentation'! |
2108 |
||
2109 |
extensionsVersion_CVS |
|
3715 | 2110 |
^ '$Header$' |
3005 | 2111 |
! ! |
3006
1847bcaf8018
Added lost method #printf_printOn:withData:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3005
diff
changeset
|
2112 |