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

Adam Kelly cthulahoops@REDACTED
Thu Oct 11 12:49:36 CEST 2007


> 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.

Rather than creating an auxilary function with a long argument list,
looking at splitting each task into its own function.  That one long
function should be four or five:

Receive a message.
Split a line of text at a colon.
Parse the data to an integer.
Format and send the data.

> The code also gets simpler when I start using erlang:list_to_integer.

Yes, but whenever you find yourself wanting a missing library
function, implement it!

list_to_integer(X) ->
  case erl_scan:string(X) of
     {ok,[{integer,1,Y}],1} -> Y;
     _ -> throw(badarg)
  end.

That way your code stays simple, and you can easily change to the
library function when you find it!

Adam.



More information about the erlang-questions mailing list