On Sun, Mar 11, 2012 at 9:58 AM, David Bruant <[email protected]> wrote:
> I'm not sure I understand what tail call optimization has to do with
> maximum stack frame.
>
> Each function call needs some memory for the scope and the function
> arguments.
> Memory is limited.
> Hence there has to be a limit in the number of nested function calls.
>
> Tail call optimization helps in reducing the number of contexts used
> under circumstances, but it doesn't change the above reasoning, does it?
With tail-call optimization, a tail call from a function will
completely remove its frame and reuse it for the next function called.
Even the return address is reused.
You can really have infinitely many recursive calls with tail-call
optimization, and it is one of the ways to make an unbounded loop in
functional languages.
Now, for this problem it is indeed irrelevant, since we are talking
about a malicious attacker, and he'll just make a function that is
recursive, but not tail-recursive (e.g., function foo() { depth++;
return 1+foo(); }) which needs to return to each calling function.
/L
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss