[erlang-questions] per function/process locals

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Wed May 2 13:21:41 CEST 2007

I haven't followed the details of this thread, but 
when dealing with records, this pattern appears quite

As it's not a great idea to export records in an API,
I often prefer to take a property list as input.
If I then still want to use a record internally for 
efficient random access, I end up having to traverse
the property list and build a record. There are 
different ways to do this:

init_state(L) ->
    fun({a, A}, S) -> S#st{a = A};
       ({b, B}, S) -> S#st{b = B};
    end, #st{}, L).

I tend to to the following, for convenience:

  [A, B, C, D] = 
    [proplists:get_value(K,L) ||
      K <- [a, b, c, d]],
  #st{a = A, b = B, c = C, d = D} 

Ulf W

> -----Original Message-----
> From: erlang-questions-bounces@REDACTED 
> [mailto:erlang-questions-bounces@REDACTED] On Behalf Of James Hague
> Sent: den 1 maj 2007 22:45
> To: erlang-questions@REDACTED
> Subject: Re: [erlang-questions] per function/process locals
> > Speaking only for myself, I find that it is a rare 
> algorithm where I 
> > need more than a handful of "variables" in a loop,
> I actually do this quite a bit.  Sometimes problems have 
> bunch of related variables, but records are awkward.  Even 
> just having 5 values getting passed around and "updated" in a 
> loop bugs me.  Editing that kind of code feels like busy work.
> I think the Erlangyest solution is to implement Joe's structs 
> proposed a few years ago, then have the compiler recognize 
> situations where structs are created and modified in a loop.
> > I'd rather have the let-for-then construct.
> Could you give an example?
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list