Is Squeak tail recursive?
Lex Spoon
lex at cc.gatech.edu
Fri Jan 29 16:57:42 UTC 1999
amoroso at mclink.it (Paolo Amoroso) wrote:
> Does the Squeak compiler generate properly tail recursive code?
>
>
I don't think so. As a defense, optimizations are generally more
complicated in Smalltalk than in non-OO languages, because of the late
binding.
In this case, suppose you have a class Bar, with a method as follows:
func: x
(x cos - x) abs < 0.0001 ifTrue: [ ^x ].
^self func: x cos
A nice, tail recursive function, right? Well, suppose we then add a
subclass Bar, which defines a new version of func: as follows:
func: x
Trascript show: x printString.
^super func: x
Well, now func: isn't always tail recursive--it depends on whether
"self" is a Foo or a Bar!
Lex
More information about the Squeak-dev
mailing list
|