[erlang-questions] conditional expressions

Richard O'Keefe <>
Tue Nov 18 04:24:10 CET 2008


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.




More information about the erlang-questions mailing list