[erlang-questions] Reading, Learning, Confused

Robert Virding rvirding@REDACTED
Tue Jul 22 15:28:07 CEST 2008

2008/7/22 Richard A. O'Keefe <ok@REDACTED>:

> As you see, using 'orelse' results in code that is CONSIDERABLY
> LESS COMPACT than code using ';'.  And it is not just less
> compact, it executes more instructions.  If compact speedy code
> is something you want, then you would have to be off your rocker
> to use 'orelse' in a guard.

I won't reproduce the code here.

The reason for this, which Richard touches on later in his message, is that
for the 'orelse' code the compiler generates code to return 'true' when the
tests succeed which is then checked at the end. This follows the semantics
of  'orelse' but is not really necessary here. In the ';' case the compiler
just generates a sequence of (inverted) tests which is in keeping how
guards, guard sequences and the tests in them were originally defined.

Note:  this might not be true for all time.
> *In a guard*, and when governing tests rather than some random
> expressions, 'orelse' should be compiled exactly like ';' and
> 'andalso' should be compiled exactly like ','.

There is some difficulty here with handling exceptions in nested
'orelse'/'andalso' which could make this a little difficult. Depending on
how you define nested ',' and ';' this may or may not be a problem.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080722/02612c86/attachment.htm>

More information about the erlang-questions mailing list