static variables?

Vlad Dumitrescu vladdu55@REDACTED
Tue Aug 22 16:15:00 CEST 2006


Hi,

You can try to use the "abstract/parametrised module" functionality.
I'm not sure if that's still available in R11, but read
  http://www.erlang.se/workshop/2003/paper/p29-carlsson.pdf#search=%22erlang%20abstract%20module%22
for details.

regards,
Vlad

On 8/22/06, Yariv Sadan <yarivvv@REDACTED> wrote:
> Hi,
>
> Strangely, I find myself at a crossroads where I would like to have
> static (i.e. per-module) variables. Yes -- I know -- this would be a
> gross violation of the shared-nothing principle -- but then I would be
> just as happy if all static variables were "final" so there's no way
> that two processes would trample on the same data.
>
> The situation is actually pretty simple: I have a 'person' module that
> corresponds to a database table. This module has a (static) list of
> fields. I would like to be able to access this static list from the
> module's functions without having to reconstruct it inside the
> function every time by calling a function such as
>
> fields() ->
>  ["name", "age"].
>
> Here's basically what I want to have:
>
> -module(person).
> -compile(export_all).
>
> fields = ["name", "age"].
>
> get_fields() ->
>  fields.
>
> Is there any way to do this in Erlang???
>
> (I looked at the process dictionary, but it is per process, not per module).
>
> Thanks,
> Yariv
>



More information about the erlang-questions mailing list