author | Claus Gittinger <cg@exept.de> |
Wed, 19 Jun 2002 14:08:24 +0200 | |
changeset 6582 | a9e74bc8c901 |
parent 6073 | a2b1c61dae18 |
child 8178 | a7ee1b47775b |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
213 | 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 |
||
5565
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
14 |
|
1 | 15 |
Object subclass:#Magnitude |
1226 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Magnitude-General' |
|
1 | 20 |
! |
21 |
||
88 | 22 |
!Magnitude class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
213 | 27 |
All Rights Reserved |
1 | 28 |
|
88 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
1 | 37 |
|
88 | 38 |
documentation |
39 |
" |
|
40 |
This is an abstract class definining common methods for |
|
41 |
Objects which can be compared by a kind of greater realation. |
|
1295 | 42 |
|
43 |
[author:] |
|
44 |
Claus Gittinger |
|
88 | 45 |
" |
46 |
! ! |
|
1 | 47 |
|
48 |
!Magnitude methodsFor:'comparing'! |
|
49 |
||
699 | 50 |
< aMagnitude |
1 | 51 |
"Compare the receiver with the argument and return true if the |
699 | 52 |
receiver is less than the argument. Otherwise return false." |
53 |
||
54 |
^ (aMagnitude > self) |
|
55 |
! |
|
1 | 56 |
|
699 | 57 |
<= aMagnitude |
58 |
"Compare the receiver with the argument and return true if the |
|
59 |
receiver is less than or equal to the argument. Otherwise return false." |
|
60 |
||
61 |
^ (self > aMagnitude) not |
|
1 | 62 |
! |
63 |
||
64 |
= aMagnitude |
|
65 |
"Compare the receiver with the argument and return true if the |
|
66 |
receiver is equal to the argument. Otherwise return false." |
|
67 |
||
68 |
^ self subclassResponsibility |
|
69 |
! |
|
70 |
||
699 | 71 |
> aMagnitude |
1 | 72 |
"Compare the receiver with the argument and return true if the |
699 | 73 |
receiver is greater than the argument. Otherwise return false." |
1 | 74 |
|
699 | 75 |
^ self subclassResponsibility |
1 | 76 |
! |
77 |
||
78 |
>= aMagnitude |
|
79 |
"Compare the receiver with the argument and return true if the |
|
80 |
receiver is greater than or equal to the argument. |
|
81 |
Otherwise return false." |
|
82 |
||
83 |
^ (aMagnitude > self) not |
|
213 | 84 |
! |
85 |
||
1226 | 86 |
clampBetween:min and:max |
87 |
"return the receiver if its between min .. max, |
|
88 |
or min if its less than min, or max of its greater than max. |
|
89 |
This is only a lazy-typers helper for: ((something min:max) max:min)" |
|
90 |
||
91 |
(self > max) ifTrue:[^ max]. |
|
92 |
(self < min) ifTrue:[^ min]. |
|
93 |
^ self |
|
94 |
||
95 |
" |
|
96 |
1 clampBetween:2 and:5 |
|
97 |
3 clampBetween:2 and:5 |
|
98 |
6 clampBetween:2 and:5 |
|
99 |
" |
|
100 |
||
101 |
"Modified: 19.4.1996 / 14:58:12 / cg" |
|
102 |
! |
|
103 |
||
699 | 104 |
max:aMagnitude |
105 |
"return the receiver or the argument, whichever has greater magnitude" |
|
106 |
||
107 |
(self > aMagnitude) ifTrue:[^ self]. |
|
108 |
^ aMagnitude |
|
109 |
||
110 |
" |
|
111 |
1 max: 2 |
|
112 |
1 max: 2.0 |
|
113 |
2.0 max: 1.0 |
|
114 |
2.0 max: 2 |
|
115 |
" |
|
116 |
! |
|
117 |
||
213 | 118 |
min:aMagnitude |
119 |
"return the receiver or the argument, whichever has lesser magnitude" |
|
120 |
||
121 |
(self < aMagnitude) ifTrue:[^ self]. |
|
122 |
^ aMagnitude |
|
123 |
||
124 |
" |
|
125 |
1 min: 2 |
|
126 |
1 min: 2.0 |
|
127 |
2.0 min: 1.0 |
|
128 |
2.0 min: 2 |
|
129 |
" |
|
1 | 130 |
! ! |
131 |
||
5565
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
132 |
!Magnitude methodsFor:'iteration'! |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
133 |
|
6073 | 134 |
downTo:stop do:aBlock |
135 |
"For each element of the interval from the receiver down to the argument stop, |
|
136 |
evaluate aBlock, passing the number as argument." |
|
137 |
||
138 |
^ self to:stop by:-1 do:aBlock |
|
139 |
||
140 |
" |
|
141 |
10 downTo:1 do:[:i | Transcript showCR:i]. |
|
142 |
" |
|
143 |
! |
|
144 |
||
5565
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
145 |
to:stop by:incr do:aBlock |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
146 |
"For each element of the interval from the receiver up to the argument stop, incrementing |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
147 |
by step, evaluate aBlock passing the element as argument." |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
148 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
149 |
|tmp| |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
150 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
151 |
tmp := self. |
6582
a9e74bc8c901
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
6073
diff
changeset
|
152 |
(incr >= 0) ifTrue:[ |
6073 | 153 |
[tmp <= stop] whileTrue:[ |
154 |
aBlock value:tmp. |
|
155 |
tmp := tmp+incr |
|
156 |
] |
|
5565
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
157 |
] ifFalse:[ |
6073 | 158 |
[tmp >= stop] whileTrue:[ |
159 |
aBlock value:tmp. |
|
160 |
tmp := tmp+incr |
|
161 |
] |
|
5565
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
162 |
] |
6073 | 163 |
|
164 |
" |
|
165 |
1 to:10 do:[:i | Transcript showCR:i]. |
|
166 |
1 to:10 by:2 do:[:i | Transcript showCR:i]. |
|
167 |
10 to:1 by:-1 do:[:i | Transcript showCR:i]. |
|
168 |
" |
|
5565
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
169 |
! |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
170 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
171 |
to:stop by:incr doWithBreak:aBlock |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
172 |
"For each element of the interval from the receiver up to the argument stop, incrementing |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
173 |
by step, evaluate aBlock passing the element as argument. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
174 |
Pass a break argument, to allow for premature exit of the loop." |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
175 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
176 |
|tmp break| |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
177 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
178 |
break := [^ self]. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
179 |
tmp := self. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
180 |
(incr > 0) ifTrue:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
181 |
[tmp <= stop] whileTrue:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
182 |
aBlock value:tmp value:break. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
183 |
tmp := tmp+incr |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
184 |
] |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
185 |
] ifFalse:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
186 |
[tmp >= stop] whileTrue:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
187 |
aBlock value:tmp value:break. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
188 |
tmp := tmp+incr |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
189 |
] |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
190 |
] |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
191 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
192 |
" |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
193 |
1 to:100 by:5 doWithBreak:[:index :break | |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
194 |
Transcript showCR:index printString. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
195 |
index > 50 ifTrue:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
196 |
break value |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
197 |
]. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
198 |
] |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
199 |
" |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
200 |
! |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
201 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
202 |
to:stop by:incr doWithExit:aBlock |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
203 |
"For each element of the interval from the receiver up to the argument stop, incrementing |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
204 |
by step, evaluate aBlock passing the element as argument. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
205 |
Pass a break argument, to allow for premature exit of the loop." |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
206 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
207 |
|tmp exit| |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
208 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
209 |
exit := [:exitValue | ^ exitValue]. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
210 |
tmp := self. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
211 |
(incr > 0) ifTrue:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
212 |
[tmp <= stop] whileTrue:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
213 |
aBlock value:tmp value:exit. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
214 |
tmp := tmp+incr |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
215 |
] |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
216 |
] ifFalse:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
217 |
[tmp >= stop] whileTrue:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
218 |
aBlock value:tmp value:exit. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
219 |
tmp := tmp+incr |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
220 |
] |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
221 |
] |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
222 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
223 |
" |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
224 |
1 to:100 by:5 doWithExit:[:index :exit | |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
225 |
Transcript showCR:index printString. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
226 |
index > 50 ifTrue:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
227 |
exit value:nil |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
228 |
]. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
229 |
] |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
230 |
" |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
231 |
! |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
232 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
233 |
to:stop do:aBlock |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
234 |
"For each element of the interval from the receiver up to the argument stop, |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
235 |
evaluate aBlock, passing the number as argument." |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
236 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
237 |
|tmp| |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
238 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
239 |
tmp := self. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
240 |
[tmp <= stop] whileTrue:[ |
6073 | 241 |
aBlock value:tmp. |
242 |
tmp := tmp+1 |
|
5565
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
243 |
] |
6073 | 244 |
|
245 |
" |
|
246 |
1 to:10 do:[:i | Transcript showCR:i]. |
|
247 |
1 to:10 by:2 do:[:i | Transcript showCR:i]. |
|
248 |
10 to:1 by:-1 do:[:i | Transcript showCR:i]. |
|
249 |
" |
|
5565
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
250 |
! |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
251 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
252 |
to:stop doWithBreak:aBlock |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
253 |
"For each element of the interval from the receiver up to the argument stop, |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
254 |
evaluate aBlock, passing the number as argument. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
255 |
Pass a break argument, to allow for premature exit of the loop." |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
256 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
257 |
|tmp break| |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
258 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
259 |
break := [^ self]. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
260 |
tmp := self. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
261 |
[tmp <= stop] whileTrue:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
262 |
aBlock value:tmp value:break. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
263 |
tmp := tmp+1 |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
264 |
] |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
265 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
266 |
" |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
267 |
1 to:10 doWithBreak:[:index :break | |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
268 |
Transcript showCR:index printString. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
269 |
index > 5 ifTrue:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
270 |
break value |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
271 |
]. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
272 |
] |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
273 |
" |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
274 |
! |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
275 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
276 |
to:stop doWithExit:aBlock |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
277 |
"For each element of the interval from the receiver up to the argument stop, |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
278 |
evaluate aBlock, passing the number as argument. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
279 |
An exitBlock is passed as second argument, which allows for the loop to be terminated early." |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
280 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
281 |
|exit tmp| |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
282 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
283 |
exit := [:exitValue | ^exitValue]. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
284 |
tmp := self. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
285 |
[tmp <= stop] whileTrue:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
286 |
aBlock value:tmp value:exit. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
287 |
tmp := tmp+1 |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
288 |
] |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
289 |
|
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
290 |
" |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
291 |
1 to:10 doWithExit:[:index :exit | |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
292 |
index == 5 ifTrue:[ |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
293 |
exit value:nil |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
294 |
]. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
295 |
Transcript showCR:index. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
296 |
]. |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
297 |
" |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
298 |
! ! |
a815d6b86ace
moved iterators up in hierarchy
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
299 |
|
1 | 300 |
!Magnitude methodsFor:'testing'! |
301 |
||
302 |
between:min and:max |
|
303 |
"return whether the receiver is less than or equal to the argument max |
|
304 |
and greater than or equal to the argument min." |
|
305 |
||
306 |
(self < min) ifTrue:[^ false]. |
|
307 |
(self > max) ifTrue:[^ false]. |
|
308 |
^ true |
|
56 | 309 |
|
213 | 310 |
" |
311 |
1.2 between:1 and:2 |
|
312 |
(3/2) between:1 and:2 |
|
313 |
(3/2) between:0 and:1 |
|
314 |
" |
|
1 | 315 |
! |
316 |
||
317 |
in:anInterval |
|
318 |
"return whether the receiver is within the interval bounds" |
|
319 |
||
320 |
(self < anInterval start) ifTrue:[^ false]. |
|
321 |
(self > anInterval stop) ifTrue:[^ false]. |
|
322 |
^ true |
|
56 | 323 |
|
213 | 324 |
" |
325 |
1.2 in:(1 to: 2) |
|
326 |
(3/2) in:(1 to: 2) |
|
327 |
(3/2) in:(0 to: 1) |
|
328 |
" |
|
1 | 329 |
! ! |
699 | 330 |
|
331 |
!Magnitude class methodsFor:'documentation'! |
|
332 |
||
333 |
version |
|
6582
a9e74bc8c901
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
6073
diff
changeset
|
334 |
^ '$Header: /cvs/stx/stx/libbasic/Magnitude.st,v 1.17 2002-06-19 12:08:24 cg Exp $' |
699 | 335 |
! ! |