author | Claus Gittinger <cg@exept.de> |
Tue, 25 Feb 1997 19:20:23 +0100 | |
changeset 2416 | 588d5d510c10 |
parent 1893 | c66af5c46272 |
child 2894 | 344aec8ba014 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
202 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
ArithmeticValue subclass:#Number |
|
973 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Magnitude-Numbers' |
|
1 | 18 |
! |
19 |
||
1892 | 20 |
!Number class methodsFor:'documentation'! |
88 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
202 | 25 |
All Rights Reserved |
1 | 26 |
|
88 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
1 | 35 |
|
88 | 36 |
documentation |
37 |
" |
|
38 |
abstract superclass for all kinds of numbers |
|
1295 | 39 |
|
40 |
[author:] |
|
41 |
Claus Gittinger |
|
1628 | 42 |
|
43 |
[see also:] |
|
44 |
Integer LargeInteger SmallInteger |
|
45 |
LimitedPrecisionReal Float ShortFloat |
|
1893 | 46 |
Fraction FixedPoint |
88 | 47 |
" |
48 |
! ! |
|
1 | 49 |
|
1892 | 50 |
!Number class methodsFor:'instance creation'! |
1 | 51 |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
52 |
readFrom:aStringOrStream onError:exceptionBlock |
1 | 53 |
"return the next Number from the (character-)stream aStream; |
202 | 54 |
skipping all whitespace first; return the value of exceptionBlock, |
55 |
if no number can be read." |
|
1 | 56 |
|
973 | 57 |
ErrorSignal handle:[:ex | |
58 |
^ exceptionBlock value |
|
339 | 59 |
] do:[ |
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
60 |
|str nextChar radix value negative signExp freakOut| |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
61 |
|
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
62 |
str := aStringOrStream readStream. |
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
63 |
|
973 | 64 |
nextChar := str skipSeparators. |
65 |
nextChar isNil ifTrue:[^ exceptionBlock value]. |
|
3 | 66 |
|
973 | 67 |
freakOut := [^ exceptionBlock value]. |
339 | 68 |
|
973 | 69 |
(nextChar == $-) ifTrue:[ |
70 |
negative := true. |
|
71 |
nextChar := str nextPeek |
|
72 |
] ifFalse:[ |
|
73 |
negative := false. |
|
74 |
(nextChar == $+) ifTrue:[ |
|
75 |
nextChar := str nextPeek |
|
76 |
] |
|
77 |
]. |
|
78 |
nextChar isDigit ifFalse:[ |
|
79 |
^ exceptionBlock value. |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
80 |
"/ value := super readFrom:str. |
339 | 81 |
"/ negative ifTrue:[value := value negated]. |
82 |
"/ ^ value |
|
973 | 83 |
]. |
84 |
value := Integer readFrom:str radix:10 onError:freakOut. |
|
85 |
nextChar := str peek. |
|
86 |
((nextChar == $r) or:[ nextChar == $R]) ifTrue:[ |
|
87 |
str next. |
|
88 |
radix := value. |
|
89 |
value := Integer readFrom:str radix:radix onError:freakOut. |
|
90 |
] ifFalse:[ |
|
91 |
radix := 10 |
|
92 |
]. |
|
93 |
(nextChar == $.) ifTrue:[ |
|
94 |
nextChar := str nextPeek. |
|
95 |
(nextChar notNil and:[nextChar isDigitRadix:radix]) ifTrue:[ |
|
96 |
value := value asFloat |
|
97 |
+ (Number readMantissaFrom:str radix:radix). |
|
98 |
nextChar := str peek |
|
99 |
] |
|
100 |
]. |
|
101 |
((nextChar == $e) or:[nextChar == $E]) ifTrue:[ |
|
102 |
nextChar := str nextPeek. |
|
103 |
signExp := 1. |
|
104 |
(nextChar == $+) ifTrue:[ |
|
105 |
nextChar := str nextPeek |
|
106 |
] ifFalse:[ |
|
107 |
(nextChar == $-) ifTrue:[ |
|
108 |
nextChar := str nextPeek. |
|
109 |
signExp := -1 |
|
110 |
] |
|
111 |
]. |
|
112 |
(nextChar notNil and:[(nextChar isDigitRadix:radix)]) ifTrue:[ |
|
113 |
value := value asFloat |
|
114 |
* (10.0 raisedToInteger: |
|
115 |
((Integer readFrom:str radix:radix onError:freakOut) * signExp)) |
|
116 |
] |
|
117 |
]. |
|
118 |
negative ifTrue:[ |
|
119 |
^ value negated |
|
120 |
]. |
|
121 |
^ value |
|
339 | 122 |
] |
1 | 123 |
|
329 | 124 |
" |
125 |
Number readFrom:(ReadStream on:'54.32e-01') |
|
126 |
Number readFrom:(ReadStream on:'12345678901234567890') |
|
127 |
Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF') |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
128 |
Number readFrom:'16rAAAAFFFFAAAAFFFF' |
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
129 |
Number readFrom:'0.000001' |
329 | 130 |
'+00000123.45' asNumber |
131 |
" |
|
569
7134eb78cf48
readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
132 |
|
1701
80d13adb2e77
better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
133 |
"Modified: 8.10.1996 / 19:24:01 / cg" |
296 | 134 |
! |
135 |
||
136 |
readSmalltalkSyntaxFrom:aStream |
|
137 |
"ST-80 compatibility (thanks to a note from alpha testers) |
|
138 |
read and return the next Number in smalltalk syntax from the |
|
329 | 139 |
(character-)stream aStream." |
140 |
||
141 |
^ Compiler evaluate:aStream compile:false "/ self readFrom:aStream. |
|
296 | 142 |
|
329 | 143 |
" |
144 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'54.32e-01') |
|
145 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'12345678901234567890') |
|
146 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF') |
|
147 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'(1/10)') |
|
148 |
Number readFrom:(ReadStream on:'(1/10)') |
|
149 |
Number readSmalltalkSyntaxFrom:(ReadStream on:'+00000123.45') |
|
150 |
Number readFrom:(ReadStream on:'+00000123.45') |
|
151 |
" |
|
1 | 152 |
! ! |
701 | 153 |
|
1892 | 154 |
!Number class methodsFor:'error reporting'! |
701 | 155 |
|
156 |
raise:aSignalSymbol receiver:someNumber selector:sel arg:arg errorString:text |
|
157 |
"ST-80 compatible signal raising. Provided for PD numeric classes" |
|
158 |
||
159 |
|msg| |
|
160 |
||
161 |
msg := MessageSend |
|
162 |
receiver:someNumber |
|
163 |
selector:sel |
|
164 |
arguments:(Array with:arg). |
|
165 |
^ (self perform:aSignalSymbol) |
|
166 |
raiseRequestWith:msg |
|
167 |
errorString:text |
|
168 |
in:thisContext sender |
|
169 |
||
170 |
" |
|
171 |
Number raise:#domainErrorSignal |
|
172 |
receiver:1.0 |
|
173 |
selector:#sin |
|
174 |
arg:nil |
|
175 |
errorString:'foo bar test' |
|
176 |
" |
|
177 |
! |
|
178 |
||
179 |
raise:aSignalSymbol receiver:someNumber selector:sel errorString:text |
|
180 |
"ST-80 compatible signal raising. Provided for PD numeric classes" |
|
181 |
||
182 |
|msg| |
|
183 |
||
184 |
msg := MessageSend |
|
185 |
receiver:someNumber |
|
186 |
selector:sel |
|
187 |
arguments:#(). |
|
188 |
^ (self perform:aSignalSymbol) |
|
189 |
raiseRequestWith:msg |
|
190 |
errorString:text |
|
191 |
in:thisContext sender |
|
192 |
||
193 |
" |
|
194 |
Number raise:#domainErrorSignal |
|
195 |
receiver:1.0 |
|
196 |
selector:#foo |
|
197 |
errorString:'foo bar test' |
|
198 |
" |
|
199 |
! ! |
|
200 |
||
1892 | 201 |
!Number class methodsFor:'private'! |
701 | 202 |
|
203 |
readMantissaFrom:aStream radix:radix |
|
204 |
"helper for readFrom: - |
|
205 |
return the mantissa from the (character-)stream aStream; |
|
206 |
no whitespace-skipping; error if no number available" |
|
207 |
||
208 |
|nextChar value factor| |
|
209 |
||
210 |
value := 0.0. |
|
211 |
factor := 1.0 / radix. |
|
212 |
nextChar := aStream peek. |
|
213 |
[nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[ |
|
214 |
value := value + (nextChar digitValue * factor). |
|
215 |
factor := factor / radix. |
|
216 |
nextChar := aStream nextPeek |
|
217 |
]. |
|
218 |
^ value |
|
219 |
! ! |
|
220 |
||
221 |
!Number methodsFor:'coercing'! |
|
222 |
||
223 |
coerce:aNumber |
|
224 |
"return aNumber converted into receivers type" |
|
225 |
||
226 |
^ self subclassResponsibility |
|
227 |
! |
|
228 |
||
229 |
generality |
|
230 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
231 |
||
232 |
^ 40 |
|
233 |
! ! |
|
234 |
||
235 |
!Number methodsFor:'converting'! |
|
236 |
||
237 |
@ aNumber |
|
238 |
"return a Point with the receiver as x-coordinate and the argument |
|
239 |
as y-coordinate" |
|
240 |
||
241 |
%{ /* NOCONTEXT */ |
|
242 |
||
243 |
/* |
|
244 |
* I cannot tell if this special code is worth anything |
|
245 |
*/ |
|
835 | 246 |
if (__CanDoQuickNew(sizeof(struct __point))) { |
701 | 247 |
OBJ newPoint; |
248 |
int spc; |
|
249 |
||
835 | 250 |
__qCheckedAlignedNew(newPoint, sizeof(struct __point)); |
1133 | 251 |
__InstPtr(newPoint)->o_class = @global(Point); |
252 |
__PointInstPtr(newPoint)->p_x = self; |
|
253 |
__PointInstPtr(newPoint)->p_y = aNumber; |
|
701 | 254 |
if (! __bothSmallInteger(self, aNumber)) { |
255 |
spc = __qSpace(newPoint); |
|
256 |
__STORE_SPC(newPoint, aNumber, spc); |
|
257 |
__STORE_SPC(newPoint, self, spc); |
|
258 |
} |
|
259 |
RETURN ( newPoint ); |
|
260 |
} |
|
261 |
%} |
|
262 |
. |
|
263 |
^ Point x:self y:aNumber |
|
264 |
! |
|
265 |
||
266 |
asPoint |
|
267 |
"return a new Point with the receiver as all coordinates; |
|
268 |
often used to supply the same value in two dimensions, as with |
|
269 |
symmetrical gridding or scaling." |
|
270 |
||
271 |
%{ /* NOCONTEXT */ |
|
272 |
||
835 | 273 |
if (__CanDoQuickNew(sizeof(struct __point))) { |
701 | 274 |
OBJ newPoint; |
275 |
||
835 | 276 |
__qCheckedAlignedNew(newPoint, sizeof(struct __point)); |
1133 | 277 |
__InstPtr(newPoint)->o_class = @global(Point); |
278 |
__PointInstPtr(newPoint)->p_x = self; |
|
279 |
__PointInstPtr(newPoint)->p_y = self; |
|
701 | 280 |
__STORE(newPoint, self); |
281 |
RETURN ( newPoint ); |
|
282 |
} |
|
283 |
%}. |
|
284 |
^ Point x:self y:self |
|
285 |
! |
|
286 |
||
2416 | 287 |
decodeAsLiteralArray |
288 |
"given a literalEncoding in the receiver, |
|
289 |
create & return the corresponding object. |
|
290 |
The inverse operation to #literalArrayEncoding." |
|
291 |
||
292 |
^ self |
|
293 |
||
294 |
"Created: 25.2.1997 / 19:17:06 / cg" |
|
295 |
"Modified: 25.2.1997 / 19:17:42 / cg" |
|
296 |
! |
|
297 |
||
701 | 298 |
degreesToRadians |
299 |
"interpreting the receiver as radians, return the degrees" |
|
300 |
||
301 |
^ (self * (Float pi)) / 180.0 |
|
302 |
! |
|
303 |
||
304 |
literalArrayEncoding |
|
1245 | 305 |
"encode myself as an array literal, from which a copy of the receiver |
306 |
can be reconstructed with #decodeAsLiteralArray." |
|
701 | 307 |
|
308 |
^ self |
|
309 |
||
310 |
"Modified: 1.9.1995 / 02:25:26 / claus" |
|
1245 | 311 |
"Modified: 22.4.1996 / 13:00:27 / cg" |
701 | 312 |
! |
313 |
||
314 |
radiansToDegrees |
|
315 |
"interpreting the receiver as degrees, return the radians" |
|
316 |
||
317 |
^ (self * 180.0) / (Float pi) |
|
318 |
! ! |
|
319 |
||
320 |
!Number methodsFor:'intervals'! |
|
321 |
||
322 |
to:stop |
|
323 |
"return an interval from receiver up to the argument, incrementing by 1" |
|
324 |
||
325 |
^ Interval from:self to:stop |
|
326 |
! |
|
327 |
||
328 |
to:stop by:step |
|
329 |
"return an interval from receiver up to the argument, incrementing by step" |
|
330 |
||
331 |
^ Interval from:self to:stop by:step |
|
332 |
! ! |
|
333 |
||
334 |
!Number methodsFor:'iteration'! |
|
335 |
||
336 |
timesRepeat:aBlock |
|
337 |
"evaluate the argument, aBlock self times" |
|
338 |
||
339 |
|count| |
|
340 |
||
341 |
count := self. |
|
342 |
[count > 0] whileTrue:[ |
|
343 |
aBlock value. |
|
344 |
count := count - 1 |
|
345 |
] |
|
346 |
! |
|
347 |
||
348 |
to:stop by:incr do:aBlock |
|
349 |
"For each element of the interval from the receiver up to the argument stop, incrementing |
|
350 |
by step, evaluate aBlock passing the element as argument." |
|
351 |
||
352 |
|tmp| |
|
353 |
||
354 |
tmp := self. |
|
355 |
(incr > 0) ifTrue:[ |
|
356 |
[tmp <= stop] whileTrue:[ |
|
357 |
aBlock value:tmp. |
|
358 |
tmp := tmp+incr |
|
359 |
] |
|
360 |
] ifFalse:[ |
|
361 |
[tmp >= stop] whileTrue:[ |
|
362 |
aBlock value:tmp. |
|
363 |
tmp := tmp+incr |
|
364 |
] |
|
365 |
] |
|
366 |
! |
|
367 |
||
919
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
368 |
to:stop by:incr doWithBreak:aBlock |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
369 |
"For each element of the interval from the receiver up to the argument stop, incrementing |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
370 |
by step, evaluate aBlock passing the element as argument. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
371 |
Pass a break argument, to allow for premature exit of the loop." |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
372 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
373 |
|tmp break| |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
374 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
375 |
break := [^ self]. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
376 |
tmp := self. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
377 |
(incr > 0) ifTrue:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
378 |
[tmp <= stop] whileTrue:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
379 |
aBlock value:tmp value:break. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
380 |
tmp := tmp+incr |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
381 |
] |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
382 |
] ifFalse:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
383 |
[tmp >= stop] whileTrue:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
384 |
aBlock value:tmp value:break. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
385 |
tmp := tmp+incr |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
386 |
] |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
387 |
] |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
388 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
389 |
" |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
390 |
1 to:100 by:5 doWithBreak:[:index :break | |
1422 | 391 |
Transcript showCR:index printString. |
919
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
392 |
index > 50 ifTrue:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
393 |
break value |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
394 |
]. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
395 |
] |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
396 |
" |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
397 |
! |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
398 |
|
701 | 399 |
to:stop do:aBlock |
400 |
"For each element of the interval from the receiver up to the argument stop, |
|
401 |
evaluate aBlock, passing the number as argument." |
|
402 |
||
403 |
|tmp| |
|
404 |
||
405 |
tmp := self. |
|
406 |
[tmp <= stop] whileTrue:[ |
|
407 |
aBlock value:tmp. |
|
408 |
tmp := tmp+1 |
|
409 |
] |
|
919
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
410 |
! |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
411 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
412 |
to:stop doWithBreak:aBlock |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
413 |
"For each element of the interval from the receiver up to the argument stop, |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
414 |
evaluate aBlock, passing the number as argument. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
415 |
Pass a break argument, to allow for premature exit of the loop." |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
416 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
417 |
|tmp break| |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
418 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
419 |
break := [^ self]. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
420 |
tmp := self. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
421 |
[tmp <= stop] whileTrue:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
422 |
aBlock value:tmp value:break. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
423 |
tmp := tmp+1 |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
424 |
] |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
425 |
|
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
426 |
" |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
427 |
1 to:10 doWithBreak:[:index :break | |
1422 | 428 |
Transcript showCR:index printString. |
919
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
429 |
index > 5 ifTrue:[ |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
430 |
break value |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
431 |
]. |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
432 |
] |
d285a0816e54
added to:do: loops with break
Claus Gittinger <cg@exept.de>
parents:
835
diff
changeset
|
433 |
" |
701 | 434 |
! ! |
435 |
||
436 |
!Number methodsFor:'printing & storing'! |
|
437 |
||
438 |
storeOn:aStream |
|
439 |
"append a string for storing the receiver onto the argument, |
|
440 |
aStream - since numbers are literals,they store as they print." |
|
441 |
||
442 |
^ self printOn:aStream |
|
443 |
! |
|
444 |
||
445 |
storeString |
|
446 |
"return a string for storing |
|
447 |
- since numbers are literals, they store as they print." |
|
448 |
||
449 |
^ self printString |
|
450 |
! ! |
|
451 |
||
452 |
!Number methodsFor:'testing'! |
|
453 |
||
454 |
isLiteral |
|
455 |
"return true, if the receiver can be used as a literal |
|
456 |
(i.e. can be used in constant arrays)" |
|
457 |
||
458 |
^ true |
|
459 |
! |
|
460 |
||
461 |
isNumber |
|
462 |
"return true, if the receiver is a kind of number" |
|
463 |
||
464 |
^ true |
|
465 |
! |
|
466 |
||
467 |
isZero |
|
1557 | 468 |
"return true, if the receiver is zero" |
469 |
||
701 | 470 |
^ self = 0 |
1557 | 471 |
|
472 |
"Modified: 18.7.1996 / 12:40:49 / cg" |
|
701 | 473 |
! ! |
474 |
||
1892 | 475 |
!Number class methodsFor:'documentation'! |
701 | 476 |
|
477 |
version |
|
2416 | 478 |
^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.39 1997-02-25 18:20:23 cg Exp $' |
701 | 479 |
! ! |