[erlang-questions] Idiomatic Erlang, style/performance question
Sat Jun 21 00:10:46 CEST 2008
On 20/06/2008, Dominic Williams <> wrote:
> ROK wrote:
>> I prefer the term "Tail-Call Optimisation" because it is more accurate.
>> The idea (as explained in "Lambda - the Ultimate Goto") is that if the
>> dynamically last thing a function does (in any language) is to return
>> the result of another function call, then there is no point in keeping
>> the current stack frame. You might as well arrange for the new
>> function to return directly to the original caller. Think of *all*
>> tail calls as "argument binding + GOTO".
> Is the optimisation possible even when the tail call is not to the same
Erlang always optimises the last call irrespective which function is
called. Apart from implementing loops as recursive functions this
feature makes some very pleasant types of programming possible, for
example finite-state machines where changing state is implemented by
the function for one state calling the function for the next state as
the last thing it does.
More information about the erlang-questions