Code generation (was NOOB)

Jay Nelson <>
Fri Sep 1 14:43:13 CEST 2006

Bjorn wrote:

> 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.

Can you describe what happens in the following two cases?

foo(X) ->
   A = [do_something(E) || E <- X],    % <1>
   [do_other(E) || E <- X],            % <2>

do_something(E) -> E * 4.

do_other(E) -> io:write("~w~n", [E]).

In 1, does the function 'do_something' every get called?
>From your description, A is thrown out and the fun has no
side effect.

In 2, does a list get created on the stack?

If 1 were changed to call 'do_other' would the code be
generated differently (because of the side effect)?


More information about the erlang-questions mailing list