Noob - Getting Started Infinte Loop?

Bjorn Gustavsson <>
Fri Sep 1 09:49:25 CEST 2006

The old Jam compiler would generate more efficient code if
the programmer wrote '_' for variables that were not used.
(Variables just prefixed with a '_' were not handled specially.)

The Beam compiler (at least from Erlang/OTP R6B) does not
need any hints from the programmer about variable usage.
In fact, '_' variables are just an annoying special case, so
the compiler gets rid of them by giving each one of them
a new, unique name.

Later, just before code generation, variable life times are
calculated. The code generator is guided by the life time information,
and doesn't generate any code for assigning a variable that
will never be used.


"Richard A. O'Keefe" <> writes:

> Note, for example, that in
>     f(X, Y) -> [ignore,X,and,Y], g(Y).
> X and Y are both used more than once.  However, a compiler could (and I
> expect at least HiPE does) notice that [ignore,X,and,Y] doesn't actually
> do anything useful, and the code you get might be the same as that for
>     f(_, Y) -> g(Y).

The Beam compiler does that optimization too. If an expression's value
is not used and the expression does not have any side effect, the expression
will be removed.


Björn Gustavsson, Erlang/OTP, Ericsson AB

More information about the erlang-questions mailing list