[erlang-questions] Reading, Learning, Confused

Darren New dnew@REDACTED
Sat Jul 19 18:59:14 CEST 2008


Edwin Fine wrote:
> of guards, it is guaranteed that leaving out the evaluation of one or 
> more guards will not change the state of the program.

I don't think that's quite right.

f(X) when (X == 0) or ((1 / X) > 2) ->
   "does not return for zero X";
f(X) when (X == 0) orelse ((1 / X) > 2) ->
   "does return for zero X".

I might be misunderstanding here, but I understand that an "abrupt 
return" from a calculation in a guard is treated the same as "false".

So in the first case, when X is 0, the guard evaluates to false, because 
1/X errors out, making the entire expression false.

In the second case, 1/X isn't evaluated when X==0, making the entire 
expression true.

It does seem like the documentation is wrong. I just tried the above 
fragment and it printed "does return" as its answer.

-- 
Darren New / San Diego, CA, USA (PST)
  Helpful housekeeping hints:
   Check your feather pillows for holes
    before putting them in the washing machine.



More information about the erlang-questions mailing list