Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of non short-circuiting boolean operators in Erlang?

I am learning Erlang from the LearnYouSomeErlang web-book. One thing that struck me while learning was the non short-circuiting boolean conjunction and disjunction operators viz; and and or. What are the use cases for these operators? Why would you want to use them instead of andalso and orelse?

like image 947
missingfaktor Avatar asked Nov 11 '11 07:11

missingfaktor


2 Answers

It used to be (until R13A) that andalso and orelse weren't tail recursive. See http://www.erlang.org/eeps/eep-0017.html for details. I don't think there is a good reason to use and/or in new programs.

like image 175
Alexey Romanov Avatar answered Nov 02 '22 12:11

Alexey Romanov


I see them as doing different things and use them as such:

  • and/or as logical operators where I want to compare the logical values. As they are strict I automatically get type-checking and I KNOW exactly what has been called.
  • andalso/orelse for control, much like && and || in C.

Seeing errors are defined in erlang I feel it is good to know what has been executed and how it went.

like image 41
rvirding Avatar answered Nov 02 '22 11:11

rvirding