« Return to Thread: comma vs andalso

Re: comma vs andalso

by Roberto Ostinelli :: Rate this Message:

Reply to Author | View in Thread


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.

r.


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

 « Return to Thread: comma vs andalso