[erlang-questions] Newbie: Is there a short-circuit for the comma operator?

James Cone <>
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
   - have all of the side-effects of exp1
   - have all of the side-effects of exp2
   - return the value of exp2


15> 0, 1.

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.

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?


More information about the erlang-questions mailing list