static variables?

Yariv Sadan yarivvv@REDACTED
Tue Aug 22 15:39:08 CEST 2006


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