[erlang-questions] Reading, Learning, Confused

Sean Allen <>
Sat Jul 19 16:51:12 CEST 2008


On Jul 19, 2008, at 10:47 AM, Edwin Fine wrote:

> You are getting twisted in knots.
>
> 1> X =0.
> 0
> 2> (X == 0) orelse (1/X > 2).
> true
> 3> f().
> ok
> 4> X = 1.
> 1
> 5> (X == 0) orelse (1/X > 2).
> false
> 8> f().
> 9> X = 0.
> 0
> 10> (X == 0) or (1/X > 2).
> ** exception error: bad argument in an arithmetic expression
>      in operator  '/'/2
>         called as 1 / 0
>
> So the orelse construct works as advertised. It will not evaluate  
> any expressions after the first false condition and prevents divide  
> by zero.

i need to reinstall because orelse doesnt for me. it works the exact  
same or.

but assuming i get a working install the reason in the example that or  
fails is because of the divide by zero correct?

which raises a new question...

why does or evaluate all the conditions? what purpose does that serve?  
when would you use or instead of orelse?




More information about the erlang-questions mailing list