Iterators? (Was: Squeak practical use? ...)
Andrew C. Greenberg
werdna at mucow.com
Thu Jan 31 02:55:37 UTC 2002
This effect can be trivially accomplished by other means:
method: aParm
self doSomeCode. . .
^self method: anExpression
-- coded as --
method: aParm
| value |
value := aParm.
[self doSomeCode. . .
value := anExpression]
repeat
The general translation, of course, always looks more gross than a more
ordinarily coded iteration. Appears to do what you want. (I don't
recall whether repeat is inlined. If not, add ". true" to the block and
replace repeat with "whileTrue"). The bottom line is that tail
recursion is semantically indistinguishable from a corresponding and
straightforward iteration.
This reduces the problem to the question whether the proposed
semantic/syntactic sugar outweighs the costs of introducing the
unfortunate notion of "pragma" to Smalltalk, or whether the cost of
automatic optimization would outweigh the benefit of losing the current,
presently expected, debugger behavior.
On Wednesday, January 30, 2002, at 02:33 PM, Jimmie Houchin wrote:
> Would it be reasonable to implement it in such a way that tail
> recursion could be explicitly requested by the programmer? The default
> would remain as it is and tail recursion could be an optimizing option.
>
> Just a thought.
>
> Jimmie Houchin
>
> Jesse Welton wrote:
>
> [snip recursion discussion]
>> I remember this being discussed here on the list some time back. It
>> sounded like it would not be difficult to change the system to enable
>> tail recursion optimization, though I don't recall whether a compiler
>> change would be sufficient, or a VM change would be necessary in the
>> general case. (I think a compiler change is sufficient, at least, for
>> self-recursive methods, but possibly not for mutual recusion.) As to
>> whether it would be a good idea, the consensus seemed to be that it
>> would interfere too much with the debugger's strengths. (Tail
>> recursion optimization effectively erases all record of intermediate
>> calls, making it much harder (or impossible) to back-trace the
>> execution of a running program.)
>> -Jesse
More information about the Squeak-dev
mailing list
|