I think you're looking for the andalso and orelse operators. You say:<br><br> X = foo() orelse bar(),<br><br>and bar() only gets called if the value of foo() is false.<br><br>-- rec --<br><br><div class="gmail_quote">
2008/11/14 damien morton <span dir="ltr"><<a href="mailto:dmorton@bitfurnace.com">dmorton@bitfurnace.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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.<div><br></div><div>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".</div>
<div><br></div><div>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()</div><div><br></div><div>I cant for the life of me figure out what the most concise way of stating that is in erlang.</div>
<div><br></div><div>perhaps</div><div> X = if (T1=foo()) =/= [] -> T1, false -> bar() end</div><div><br></div><div>it would nice to be able to say something like</div><div> X = foo() otherwise bar().<br></div><div>
<br>
</div><div>or somesuch</div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br>