[erlang-questions] conditional expressions

damien morton dmorton@REDACTED
Sat Nov 15 01:38:47 CET 2008


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081115/f1642e59/attachment.htm>


More information about the erlang-questions mailing list