210 "evaluate the argument, aBlock for every element in the |
210 "evaluate the argument, aBlock for every element in the |
211 receiver-interval. |
211 receiver-interval. |
212 Redefined since SeqColl accesses the receiver with at:, which is |
212 Redefined since SeqColl accesses the receiver with at:, which is |
213 slow for intervals." |
213 slow for intervals." |
214 |
214 |
215 |aValue| |
215 |aValue iter| |
216 |
216 |
217 aValue := start. |
217 aValue := start. |
218 step < 0 ifTrue:[ |
218 aValue isInteger ifTrue:[ |
219 [stop <= aValue] whileTrue:[ |
219 step < 0 ifTrue:[ |
220 aBlock value:aValue. |
220 [stop <= aValue] whileTrue:[ |
221 aValue := aValue + step |
221 aBlock value:aValue. |
222 ] |
222 aValue := aValue + step |
|
223 ] |
|
224 ] ifFalse:[ |
|
225 [stop >= aValue] whileTrue:[ |
|
226 aBlock value:aValue. |
|
227 aValue := aValue + step |
|
228 ] |
|
229 ] |
223 ] ifFalse:[ |
230 ] ifFalse:[ |
224 [stop >= aValue] whileTrue:[ |
231 "/ the code below avoids rounding errors |
225 aBlock value:aValue. |
232 "/ to accumulate if floats are enumerated. |
226 aValue := aValue + step |
233 iter := 1. |
227 ] |
234 step < 0 ifTrue:[ |
|
235 [stop <= aValue] whileTrue:[ |
|
236 aBlock value:aValue. |
|
237 aValue := start + (iter * step). |
|
238 iter := iter + 1. |
|
239 ] |
|
240 ] ifFalse:[ |
|
241 [stop >= aValue] whileTrue:[ |
|
242 aBlock value:aValue. |
|
243 aValue := start + (iter * step). |
|
244 iter := iter + 1. |
|
245 ] |
|
246 ] |
228 ] |
247 ] |
|
248 |
|
249 " |
|
250 1e7 to:1e7+1 by:0.25 do:[:v | Transcript showCR:v] |
|
251 1.0 to:2.0 by:0.25 do:[:v | Transcript showCR:v] |
|
252 2.0 to:1.0 by:-0.25 do:[:v | Transcript showCR:v] |
|
253 " |
229 ! |
254 ! |
230 |
255 |
231 select:aBlock |
256 select:aBlock |
232 "evaluate the argument, aBlock for every element in the collection |
257 "evaluate the argument, aBlock for every element in the collection |
233 and return a collection of all elements for which the block return |
258 and return a collection of all elements for which the block return |