Re:SICP Goodness – Why you don't need looping constructs
by yvdriess on Friday June 29, 2018 @08:02AM
(#17423974)
While there isn't special form for tailcall, they are not implicit. If the recursive call does something with the result, it's not a tailcall. Unless you are being cute with closures, it's already explicit in the AST.
But there is indeed something to be said about a construct that enforces the tail call guarantee. The point of SICP's scheme though is to keep the number of language constructs to a minimum for educational purposes.
[ Parent
| on HN ]
Re:SICP Goodness – Why you don't need looping constructs
by nabla9 on Friday June 29, 2018 @08:36AM
(#17424124)
the following is also tailcall:
x = f(a)
...
...
return x
Re:SICP Goodness – Why you don't need looping constructs
by steinuil on Friday June 29, 2018 @09:24AM
(#17424330)
That's definitely not a tail call, and even with a smart compiler it's pretty hard that it would get optimized into "return f(a)".
If "x" is declared there and never mutated in the subsequent code, and the code in the "..." doesn't perform any side effects, then such an optimization could occur... but then again, if the code in the "..." in your example didn't perform any side effects, it'd be dead code.
Re:SICP Goodness – Why you don't need looping constructs
by nabla9 on Friday June 29, 2018 @11:18AM
(#17424994)
Better examples:
Both
If (b == 3):
x = f(a)
else:
x = g(a)
return x
and if (b == 3):
x = f
else:
x = g
return x(a)
are equivalent to: if (b == 3):
return f(a)
else:
return g(a)
In every example the function call is in the tail position semantically. In the the two cases syntactically. The loop construct is hidden.