[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Tailcall
- From: ramsdell@... (John D. Ramsdell)
- Date: 27 Dec 2001 09:41:36 -0500
Jay Carlson <nop@nop.com> writes:
> In the context of Lua, it bothers me to have such an important
> distinction made solely by statement position. Would treturn or tail
> statements help?
I thought that in Lua, a call is in tail position if and only if it in
a statement of the form:
return CALL-EXPRESSION
That is, the string of tokens that form the expression following the
return keyword is recognized by the parser as a single procedure call.
Procedure calls in all other places in Lua are not tail calls, even if
no code follows them. This is because the return stack may need
adjustment. Thus, in
function wrapper(i)
not_tail(i)
end
not_tail may return values, so the stack frame associated with
wrapper must remain active so that it can flush those return values.
In short, Lua provides a syntactic clue as to when a call is in tail
position. Determining which calls are in tail position in Scheme is a
little more complicated.
John