[erlang-questions] how: Another library flatten function?

Björn Gustavsson bgustavsson@REDACTED
Sun Feb 28 08:36:54 CET 2010

2010/2/28 Robert Virding <rvirding@REDACTED>:
> Yes, somewhere you have to have a stack. Either you use the call stack
> or you explicitly handle your own stack, in this case with a list. In
> essence you are doing the same when you push the output onto the front
> of a list which you reverse at the end, you are handling your own
> stack.

Using the call stack (i.e. doing recursive calls) used to be much slower in
older versions of Erlang/OTP. Since R12B the difference is
smaller, and body-recursive calls can even be faster than tail-recursive
calls. If you really need to have the fastest possible program, you
will need to implement both a body-recursive and tail-recursive version
and measure. If speed is not that important, I would recommend
going for the clearest and most readable implementation.

See the Efficiency Guide (2.3 Myth: Tail-recursive functions are MUCH
faster than recursive functions) for more details:


Björn Gustavsson, Erlang/OTP, Ericsson AB

More information about the erlang-questions mailing list