[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: requiring proper tail recursion
In the example:
>In the following example the only tail call is the call to F.
>None of the calls to G or H are tail calls. The reference to
>X is in a tail context, but it is not a call and thus is not a
>tail call. Implementations are allowed, but not required, to
>recognize that some non-tail calls, such as the call to H below,
>can be evaluated as though they were tail calls.
>
> (lambda ()
> (if (g)
> (let ((x (h)))
> x)
> (and (g) (f))))
If H returns multiple values, (let ((x (h))) x) is not equivalent to
(h), as the last sentence implies, is it?
Assuming that can be fixed, I found the remark about the call to H
quite confusing at first; would be appropriate to drop a hint as to
why H is special? As in:
In the following example the only tail call is the call to F.
None of the calls to G or H are tail calls. The reference to
X is in a tail context, but it is not a call and thus is not a
tail call.
(lambda ()
(if (g)
(let ((x (h)))
x)
(and (g) (f))))
Analysis of an expression may reveal that some calls, although not
syntactically in a tail context, can still use the calling
procedure's continuation directly. For example, the call to H
above is not in a tail context, but its value is always returned
directly by the procedure to which the LAMBDA expression
evaluates, so the entire LET expression may be evaluated like a
tail call to H. Implementations are allowed, but not required, to
recognize that some non-tail calls, such as the call to H above,
can be evaluated as though they were tail calls.
Perhaps the remark about H should be dropped. It's interesting, but
also confusing, not quite accurate, and unnecessary; it's already
clear that implementations are allowed to do optimizations not
suggested by the report.