[erlang-questions] comma vs andalso
Roberto Ostinelli
roberto@REDACTED
Mon Jul 6 15:25:50 CEST 2009
On 06/lug/09, at 15:21, Hynek Vychodil wrote:
> It seems no difference for me:
>
> 1> F = fun(X) when X=/=0, 1/X > 0.1 -> true; (_) -> false end.
> #Fun<erl_eval.6.13229925>
> 2> F2 = fun(X) when X=/=0 andalso 1/X > 0.1 -> true; (_) -> false end.
> #Fun<erl_eval.6.13229925>
> 3> [ F(X) || X <- [0, 0.0, 0.1, 10, 9]].
> [false,false,true,false,true]
> 4> [ F2(X) || X <- [0, 0.0, 0.1, 10, 9]].
> [false,false,true,false,true]
>
> --
> --Hynek (Pichi) Vychodil
yes, at it has been pointed out by richard already:
On 06/lug/09, at 15:10, Richard Carlsson wrote:
> and will not evaluate the subsequent tests if one test fails. If
> there are alternatives expressed with semicolon, the next such
> alternative will be tried instead; otherwise, the whole guard fails.
>
> What you describe is true for the 'and' operator compared to
> 'andalso'.
my fault.
as you can see:
1> F3 = fun(X) when X=/=0 and (1/X > 0.1) -> true; (_) -> false end.
#Fun<erl_eval.6.13229925>
2> [ F3(X) || X <- [0, 0.0, 0.1, 10, 9]].
[false,false,false,false,false]
r.
More information about the erlang-questions
mailing list