[erlang-questions] Newbie: Is there a short-circuit for the comma operator?
James Cone
jcone@REDACTED
Wed Oct 10 08:14:11 CEST 2007
Hello All,
This isn't explicit in the Erlang Reference Manual (v5.5.5), so you may
not think of it this way:
There is (something morally equivalent to) an operator ",", which is the
lowest priority of all operators, and the evaluation of
exp1, exp2
is:
- have all of the side-effects of exp1
- have all of the side-effects of exp2
- return the value of exp2
eg
15> 0, 1.
1
16>
Is there an operator or function that short-circuits the comma operator,
so if exp1 uses it, exp2 will not be evaluated?
eg (supposing it's called return, which is the name of the equivalent
operator in C)
> if 1==0 -> -1; true -> return 0 end, 1.
1
>
I want this because I have a function with some deeply nested tests, and
I want to tail-recurse from only some of the cases, without copying all
of the following expressions (after a comma operator) into all of the
other cases.
Am I making sense? Does such a thing exist?
Regards,
James.
More information about the erlang-questions
mailing list