tail recursion

Lex Spoon lex at lexspoon.org
Fri May 18 16:38:08 UTC 2007


Lex Spoon <lex at lexspoon.org> writes:
> Tony Garnock-Jones <tonyg at lshift.net> writes:
> > To me it's not a question of optimisation, but a question of not being
> > able to express useful patterns of control flow directly. Instead, I am
> > forced to encode them, often using otherwise-avoidable mutable state.
> 
> In Squeak, you should feel free to write recursive routines anyway.

On second thought, let me ammend this.  You should mostly feel free to
write tail-recursive functions.  However, you must consider that you
will use up lots of heap.

You will not blow stacks, though.  And if you are recursing through a
data structure, then the heap usage will be no larger than the size of
the data structure.

On the other hand, don't write an infinite loop in tail-recursive
style in Squeak!  For example, this idiom works in Scheme but not
in Squeak:

  eventLoop
    self processEvent.
    ^self eventLoop


-Lex




More information about the Squeak-dev mailing list