Is Squeak tail recursive?

Mark Wai mwai at ibm.net
Thu Jan 28 15:49:01 UTC 1999


At 12:40 PM 1/28/99 GMT, you wrote:
>Does the Squeak compiler generate properly tail recursive code?

I believe the answer is no.  It can support neither tail nor head resursion. 

It is because the current Block implementation in Squeak (i.e. BlockContext)
is non-reentrant.  The reason being the block object contains its own states
(e.g. temporary variables, instruction pointer etc.) and therefore, multiple
calls/activations of the same block object will not be possible since
subsequent calls will overwritten the previous call's states.  

In Squeak, it will cause a walkback as soon as BlockContext detected that
the execution has already been evaluated.  The good news is,  I believe that
some people are working (or have already done) on fixing this problem (e.g.
adding Closure object).

For reference, take a look at VisualWork Smalltalk (www.objectshare.com).
IMHO, It has one of the better Block/BlockClosure implementation (with
optimization).  Also refer to the blue book (www.ipa.net\dwight) for a
detailed description of Smalltalk-80 based block implementation.

--
Mark Wai
Wator InnoVision





More information about the Squeak-dev mailing list