Help-me
Ulf Wiger
etxuwig@REDACTED
Tue Apr 3 09:52:57 CEST 2001
On Tue, 3 Apr 2001, Raimo Niskanen wrote:
>Well,
>
>you can't do arrays in Erlang. Since Erlang is a functional
>programming language, mutable data structures (such as arrays) are
>not available in the language. The closest resembling data
>structures are ETS tables and the process dictionary. Both are
>accessed through BIFs (Built In Functions). The process dictionary
>can be quite a fast array if it is not too big.
For small arrays, you can use a tuple:
array(Size) -> erlang:make_tuple(Size).
read(Pos, Array) -> element(Pos, Array).
write(Pos, Array, Value) -> setelement(Pos, Array, Value).
But performance for write/3 will not be that great for bigger arrays.
On http://www.erlang.org, under "User Contributions", you can find
something called dynarray. It's a dynamically sized array-like
structure that works like the small example above.
Or, use ETS or process dictionary as Raimo suggests.
Perhaps you could clarify why you need a semaphore?
/Uffe
--
Ulf Wiger tfn: +46 8 719 81 95
Senior System Architect mob: +46 70 519 81 95
Strategic Product & System Management ATM Multiservice Networks
Data Backbone & Optical Services Division Ericsson Telecom AB
More information about the erlang-questions
mailing list