static variables?

Ulf Wiger (TN/EAB) <>
Tue Aug 22 16:06:19 CEST 2006


You can do this with parameterized modules.

http://www.erlang.se/workshop/2003/paper/p29-carlsson.pdf

I believe the implementation in OTP R10 and R11 pretty
much follows the proposal.

BR,
Ulf W 

> -----Original Message-----
> From:  
> [mailto:] On Behalf Of Yariv Sadan
> Sent: den 22 augusti 2006 15:39
> To: erlangquestions
> Subject: static variables?
> 
> 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