[erlang-questions] guard clause oddity, maybe bug (in my brain)?

Kenneth Lakin kennethlakin@REDACTED
Sat Nov 21 07:16:52 CET 2015


On 11/20/2015 08:27 PM, Jim wrote:
> 
> Thank you both, I guess I don't  fully understand the associative and precedence of these operators.

This seems a sensible way to look at it:

1> false andalso false orelse true.
true
2> ((false andalso false) orelse true).
true
3> (false andalso (false orelse true)).
false

andalso and orelse are described in the docs as

Expr1 orelse Expr2
Expr1 andalso Expr2

You *have* to have two expressions for a given andalso/orelse, so you
read expression 1 up there from left to right.
First evaluate
false andalso false (which is -obviously- false, and becomes the Expr1
of the next expression)
Then evalutate
false orelse true (which is true)

Does that make sense?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151120/aa9a565d/attachment.bin>


More information about the erlang-questions mailing list