Elemental expression Erlang boolean

I still find my feet with erlang and I read the documentation about using the "and", "or" operators, but why doesn't the following evaluate?

X = 15, Y = 20, X==15 and Y==20. 

I expect "true" in the terminal, but I get a "syntax error before ==".

+4
source share
4 answers

Try:

 X = 15. Y = 20. (X==15) and (Y==20). 
+10
source

You probably don't want to use and. There are two problems, and, firstly, since you noticed that its priority is strange, and secondly, it does not close its second argument.

 1> false and exit(oops). ** exception exit: oops 2> false andalso exit(oops). false 

and was also introduced later into the language and behaves in a way that is probably more familiar. In general, use andalso if you have no good reason to prefer and.

Btw, orelse is the equivalent of or.

+8
source

Without braces you can also do

 X = 15. Y = 20. X == 15 andalso Y == 20. 
+5
source

All Articles