« Return to Thread: comma vs andalso

Re: comma vs andalso

by whongo@gmail.com :: Rate this Message:

Reply to Author | View in Thread

On Jul 6, 3:25 pm, Roberto Ostinelli <robe...@...> wrote:

>
> 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]

Ah, but that's because the expression (0 and (1/X > 0.1)) is bad.
(I've learned to be very afraid of how strongly 'and' binds. ;))

By contrast,

25> F4 = fun(X) when (X =/= 0) and (1/X > 0.1) -> true; (_) -> false
end.
#Fun<erl_eval.6.13229925>
26> [ F4(X) || X <- [0, 0.0, 0.1, 10, 9]].
[false,false,true,false,true]

And to iterate my previous point,

28> F5 = fun(X) when 1/X > 0.1 -> true; (_) -> false end.
#Fun<erl_eval.6.13229925>
29> [F5(X) || X <- [0, 0.0, 0.1, 10, 9]].
[false,false,true,false,true]


________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

 « Return to Thread: comma vs andalso