[erlang-questions] comma vs andalso
Mon Jul 6 14:19:59 CEST 2009
On 06/lug/09, at 13:13, Joel Reymont wrote:
> I noticed that inets code uses
> foo(...) when Condition1 andalso Condition2 -> ...
> Is the comma deprecated? For example, why not
> foo(...) when Condition1, Condition2 -> ...
the difference is very simple. comma indicates that both guard
operators need to be evaluated, while on the contrary 'andalso' means
that the second condition is evaluated ONLY if condition1 is true.
same goes for 'orselse'.
this is particularly relevant when condition2 would result for
instance in an evaluation error if condition1 is not met, as in:
foo(..) when (islist(X) == true ansalso (lists:nth(1,X) == 'test') -> ..
hope this clears.
More information about the erlang-questions