Constant lists

Richard Carlsson richardc@REDACTED
Tue Jul 4 14:10:27 CEST 2000

On Sun, 25 Jun 2000, James Hague wrote:

> In Erlang, if you want to have a constant, medium-sized list, what's the 
> best way of dealing with it?  In Lisp, for example, you use defparameter 
> to define a list and then reference it when you need it.
> In Erlang, you could do this:
> constant_list() -> [item1, item2, item3, item4, ...].
> but then that list is actually created each time you call it, which is 
> messy.  It's not really a constant in this case.  For association lists, 
> you could code it in a Prolog style:
> name(john) -> 7;
> name(bjorn) -> 3;
> name(james) -> 9.
> but this isn't general.  Or, you could read the term from disk, but then 
> only the current process has access to it.  Putting it in a global ets 
> table results in the list being copied each time it is fetched.
> Sure would be nice to have honest-to-goodness constant lists and tuples.  
> Any thoughts?
> James

This is something that the compiler should detect and handle better (by
creating a static structure instead of generating code to rebuild it at
each call), but it also requires that the garbage collector can handle
special memory areas for constant data, so it is not all that easy to
implement. The same problem occurs with e.g. floating-point constants. We
are working on it in HiPE, but I don't know about coming releases of OTP.
Björn? Robert? 

	/Richard Carlsson

Richard Carlsson (richardc@REDACTED)   (This space intentionally left blank.)
E-mail: Richard.Carlsson@REDACTED	WWW:

More information about the erlang-questions mailing list