[erlang-questions] Erlang Core question: nested expressions vs. let?

Robert Virding <>
Thu Apr 17 17:56:32 CEST 2008


On 17/04/2008, Dimitry Golubovsky <> wrote:
>
> Hi,
>
> Would be there any difference in compilation/execution of bytecode of
> these two Erlang Core expressions:
>
> 1.  foo(bar(_a))
>
> 2. let _b = bar(_a) in foo(_b)
>
> In other words, does putting nested expressions in `let' make any
> difference for the compiler?
>
> Assume that both `foo' and `bar' functions do not have side effects.


One reason (the main reason :-)) the compiler does this is to make explicit
the evaluation order of called functions. Erlang is defined to evaluate in a
left-to-right order while in Core, if I remember correctly, the order is
undefined; therefore the need of explicit ordering.

Note that Core has no problems in compiling the nested forms, as you have
noticed. For LFE I don't bother to un-nest it, although I probably should.
You should at the resultant code when you deep nesting interlaced with
list/tuple creation, the result is quite good.

Robert


Thanks.
>
> PS The nested form compiles fine by erlc, however when I look at what
> erlc produces when run with +to_core on an Erlang source, there are
> only `let' forms in the generated Core. My Core files are either
> hand-written or auto-generated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080417/fab2646f/attachment.html>


More information about the erlang-questions mailing list