[erlang-questions] some language changes

Thomas Lindgren thomasl_erlang@REDACTED
Mon Jun 4 18:16:31 CEST 2007


--- James Hague <james.hague@REDACTED> wrote:

> Robert Virding wrote:
> > Why is it less ugly. The problem is not whether
> the BEAM supports but if
> > it fits and we want it. You could probably add a
> lot of stuff if go
> > after what the BEAM supports.
> 
> I commonly see code like this, even in OTP:
> 
> {Hours, Rest1} = parse_integer(L),
> Rest2 = parse_char(Rest1, $:),
> {Minutes, Rest3} = parse_integer(Rest2),
> etc.
> 
> The RestN variables are just hacks, IMO, and make
> the code hard to
> read and maintain.  I know there are other ways of
> writing this code,
> but this is the straightforward "Erlang way."

I tend to write code like the above, and find that
it's usually okay when the code looks regular.
Occasionally, it's even useful to have Rest3 available
beyond the usual scope.

Another approach is to use something monad-y or linear
to hide the RestN plumbing. Syntax for that a la
Haskell?

(The super-erlang way is of course to encapsulate the
state in a process. That way, you can even write it
as:

parse_time(Str) ->
   %% Str is a process holding the input string
   %% parse_* internally use send/receive vs Str
   Hours = parse_integer(Str),
   parse_char(Str, $:)
   Minutes = parse_integer(Str),
   {Hours, Minutes}.

No language changes needed.)

Best,
Thomas



      ____________________________________________________________________________________
Shape Yahoo! in your own image.  Join our Network Research Panel today!   http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 





More information about the erlang-questions mailing list