# Old style vs. new style boolean expressions

Robert Virding robert.virding@REDACTED
Thu Oct 10 02:02:32 CEST 2002


James Hague wrote:
>>I don't think this make much of a difference most of the 
>>time, and even if it
>>increases the size noticeably - does it matter ?
> 
> 
> It only matters to people who obsessively peek behind the scenes :)
> 
> Possibly, though, it could be a flaw in or weakness in the compiler.  I
> would think that _most_ complex boolean guards could be mechanically
> transformed into "classic" Erlang pattern matching, so the resulting code
> should be very similar.  The Erlang compiler is pretty amazing most of the
> time.

Yes, they can. What really happens is that most classical guards are 
actually tranformed into boolean guard expressions. However, what you 
were describing were boolean *expressions*! You transformed a function 
with guards into functions with boolean expressions. It is only in a 
restricted case where boolean epressions can be transformed into guards. 
Expressions are much more general and handle faults in a completely 
different way.

Actually an expression -> guard transofrmation is (rather naively) done 
in list comprehensions.

One reason that the andthen/orelse expressions resulted in so much code 
is that they are transformed into nested cases. Try using the 'E' option 
to the compiler and look at the .E file.

Robert






More information about the erlang-questions mailing list