[erlang-questions] comma vs andalso

Richard Carlsson <>
Mon Jul 6 15:10:16 CEST 2009


Roberto Ostinelli wrote:
> 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'.

No, the comma separator in guards also uses short-cut evaluation
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'.

    /Richard


More information about the erlang-questions mailing list