[erlang-questions] potential compiler improvement?

James Hague james.hague@REDACTED
Mon Oct 26 21:18:14 CET 2009


> > test({A, B, C, D, E, F, G}) ->
> >    case A of
> >       this -> B + C + D;
> >       that -> E + F + G
> >    end.
>
> I don't know much about the compiler, but I think it hasn't got the
> slightest idea of A being 'this', 'that' or something completely
> different, so it can't really optimize.

You don't need to know the value of A ahead of time. You simply don't
unpack B, C, D until you're in the 'this' branch (and once you've gone
down that path then you know you don't need to bother unpacking E, F,
G).


More information about the erlang-questions mailing list