[erlang-questions] Tail call optimization
Mon Oct 17 14:00:43 CEST 2016
In the doc page you linked:
> If the last expression of a function body is a function call, a *tail
recursive* call is done.
Compiler will replace call opcode with a tail call (call_last,
call_ext_last, apply_last). You can check it with "erl -S test.erl" to see
assembly, and in erl console: "l(modulename)." to load the module then
"erts_debug:df(modulename)." to create disassembly from BEAM VM memory (it
will be a bit different from the erl -S output).
See that your calls are replaced with one of: call_last, call_ext_last,
2016-10-17 10:58 GMT+02:00 Salikhov Dinislam <
> Erlang guarantees tail recursion optimization and states it in the
> Does erlang guarantee that tail call optimization is done in a generic
> case, without recursion?
> Say, we have a function calling a function from another module as its
> final statement:
> alpha() ->
> Is it guaranteed that xxx:beta() will use the stack of alpha() regardless
> whether recursion is involved.
> I mean whether the language guarantees it rather than virtual machine may
> provide such optimization.
> Thanks in advance,
> Salikhov Dinislam
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions