["BUG"][FIX?]Incorrect Pseudo-Code for #whileTrue:/#whileFalse:?
Andrew C. Greenberg
werdna at mucow.com
Mon Jan 1 18:29:44 UTC 2001
It's possible that I'm just not getting it, but it would appear that
the pseudo-code for #whileTrue; and #whileFalse: is incorrect. Even
if I were right, it is still the height of pedantry on my part to
call this a bug, since the code is never executed due to compiler
inlining. Nevertheless, perhaps it would be more aesthetically
pleasing to have pseudo-code here that would work if the compiler did
not inline loops?
The present code in BlockContext is:
>whileTrue: aBlock
> "Ordinarily compiled in-line, and therefore not overridable.
> This is in case the message is sent to other than a literal block.
> Evaluate the argument, aBlock, as long as the value of the
>receiver is true."
>
> ^ [self value] whileTrue: [aBlock value]
But it would appear to me that this code would infinite loop for so
long as these valuations do not result in a walkback. In either case
the behavior appears both undefined and incorrect for most
BlockContext instances and arguments. Perhaps something like the
following would yield the desired result?
^ self value ifTrue: [aBlock value. self whileTrue: aBlock]
(and in the case of #whileFalse, use #ifFalse instead).
More information about the Squeak-dev
mailing list
|