[BUG]?SequenceableCollection>>after:ifAbsent: comment vs code
tblanchard at mac.com
tblanchard at mac.com
Tue Sep 9 22:58:27 UTC 2003
One of these is wrong - either the comment or the code - I'd like to
say its the code and change it. But I'd like the opinions of others
first. I'm performing a set of tasks on each element in the collection
by dropping the element into a queue and when its done doing its thing
it calls back to say its finished.
The collection owner then finds the next element in the collection and
queues it up. Or it would except that on the last element it signals
an error because there is no element after. Of course, at that point I
expect the exceptionBlock to be evaluated. That's what the comment
says happens too. But as you can see that's not what it does.
after: target ifAbsent: exceptionBlock
"Answer the element after target. Answer the result of evaluation
the exceptionBlock if target is not in the receiver, or if there are
no elements after it."
| index |
index _ self indexOf: target.
^ index == 0
ifTrue: [exceptionBlock value]
ifFalse: [index = self size
ifTrue: [self errorLastObject: target] "THIS is the problem line I
think - it should evaluate exceptionBlock"
ifFalse: [self at: index + 1]]
More information about the Squeak-dev
mailing list
|