[erlang-questions] conditional expressions

Serge Aleynikov <>
Tue Nov 18 04:38:49 CET 2008


Your 'must' statement is not entirely accurate.  Consider this:

1 == 2 orelse throw(no_bool_return).



Richard O'Keefe wrote:
> On 15 Nov 2008, at 2:13 pm, Roger Critchlow wrote:
> 
>> I think you're looking for the andalso and orelse operators.  You say:
>>
>>   X = foo() orelse bar(),
>>
>> and bar() only gets called if the value of foo() is false.
> 
> However there is a strong restriction in Erlang that does not
> exist in Lisp, Scheme, Smalltalk, &c and does not exist in
> Python.
> 	False or 42		=> 42 in Python
> 	42 or False		=> 42 in Python
> 	1 == 2 orelse 42	=> ERROR! in Erlang
> 	42 orelse 1 == 2	=> ERROR! in Erlang
> 
> In Erlang, both operands of an andalso or orelse operator
> must return 'true' or 'false'.  I strongly suspect that the
> OP wants a non-empty list or tuple to count as true, rather
> than as an error.
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 




More information about the erlang-questions mailing list