[erlang-questions] naive execution of guards

Thomas Lindgren thomasl_erlang@REDACTED
Tue Dec 12 23:06:33 CET 2006


--- Toby Thain <toby@REDACTED> wrote:

> 
> On 12-Dec-06, at 1:35 PM, Thomas Lindgren wrote:
> 
> >
> > --- "Ulf Wiger (TN/EAB)" <ulf.wiger@REDACTED>
> > wrote:
> >
> >>
> >> I was curious to see whether the compiler would
> >> optimize away repeated
> >> use of the length/1 guard, e.g in the following
> >> code:
> > ...
> >> I'm sure it's tricky, and I don't know if the
> above
> >> reasons are strong
> >> enough.
> >
> > Actually, this optimization is ordinary
> elimination of
> > common subexpressions, and so should be relatively
> > straightforward to implement.
> 
> Especially since the subexpressions are already
> guaranteed side- 
> effect free (right?)
> :)
> --Toby

Igzackly, it's one of the few wins from having
restricted guards. CSE of generalized guards or
expressions would have to be more conservative (or
rather, you could optimize _the_same_ guard the same
way, because it's pure, but you can't do such CSE for
any old function call).

Best,
Thomas



 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com



More information about the erlang-questions mailing list