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

Raimo Niskanen raimo+erlang-questions@REDACTED
Thu Oct 11 09:24:00 CEST 2007


On Thu, Oct 11, 2007 at 07:05:21PM +1300, James Cone wrote:
> Thanks; I like auxilliary functions as a general technique.  The only 
> way it doesn't scale is the shopping-list of command-line arguments, and 
> I guess the answer to that is records.

Shopping-list?

English is not my native language, so I assume you mean the number of
function arguments tends to grow to painful numbers. In that case:
yes, records can help.

But if you get a very long list of function arguments you should
think again. Perhaps the cut between the functions can be made
at a different place. Fewer arguments tends to give more
maintainable code since the programmer gets a smaller
state to keep in the head when understanding the code.

Somtimes helper functions like the one I suggested take a
lot of arguments just to be able to do the tail recursion,
but do not use them themselves. In that case there might
be a different function structure with a few arguments to the
helper function, and a few (or one) return value that indicate
if tail recursion should be done, and the calling
function does the tail recursion.



> 
> The code also gets simpler when I start using erlang:list_to_integer. 
> Should something like that be in the getting-started manual, near 
> io:format()?
> 
> >> Raimo, I may have miscommunicated; I don't want the returned value; what 
> >> > I'm trying to achieve is to be tail-recursive from the middle of an if, 
> >> > where the non-recursing branches will evaluate another expression, after 
> >> > a comma-operator.  So throw/catch requires that I fail, because the 
> >> > stack frame will still be there, to catch the thrown thing.
> > 
> > In that case the standard solution is to restructure the code,
> > create a support function See below.
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list