> On Dec 27, 2014, at 9:34 PM, michael <
michae...@gmail.com> wrote:
>
> I am slowly making my way through the book and wanted to know about the tail call optimisation of the 'add-new-dice' function on page 333/4.
>
> Is it optimised because the first conditional argument is a (zerop n) not the (null lst), ie testing an atom not a list? Is that part of the optimisation? It seems to be only mentioned briefly in the book.
>
> And from my searching online I've just found mentions of the work that the compiler does. But I got the impression, it's mainly about the style that code is written in.
The key point for tail call optimization is that the return value of
the recursive call is returned directly from the calling function.
In that’s sense, it’s a matter of programming style, in that the
function was written that way. But the style makes possible the
tail call optimization, in which the compiler generates code that
doesn’t have to keep the intermediate stack frame around, since
the return value of the tail call is the return value of the function.
Hope this helps.
Win