[erlang-questions] conditional expressions

Roger Critchlow <>
Sat Nov 15 02:13:40 CET 2008


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.

-- rec --

2008/11/14 damien morton <>

> I keep wanting to have python-like boolean expression evaluation, in which
> a value of nil, 0, an empty list or an empty tuple are considered to be
> false.
> It would be great to have a consise way of saying "the value of this
> expression is expr1 if expr1 evaluates to a non-false value, or expr2
> otherwise".
>
> In python, you would say "X = foo() or bar()", which would evaluate foo(),
> and if that evaluates to one of None,False,0,[],(),{}, then evaluate bar()
>
> I cant for the life of me figure out what the most concise way of stating
> that is in erlang.
>
> perhaps
>  X = if (T1=foo()) =/= [] -> T1, false -> bar() end
>
> it would nice to be able to say something like
>  X = foo() otherwise bar().
>
> or somesuch
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081114/d0d7766e/attachment.html>


More information about the erlang-questions mailing list