Help-me

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Help-me

Colégio Divina Providência
    Dear Srs.
     Please, I'm a graduate student of Computer Cienci in
State of Santa Catarina Brazil, I need developer a Work of
Erlang Language.
    Wel,  I like know who I do array in Erlang?
    and I need developer a work of producer and consumer whit erlang using semaphores
    Please Reply me  and help-me..
 

    Thangs ...

Marcio Luiz Ferreira
Studant of Computing Cience of University of FURB
Fundation University Regionary of Blumeau  SC - Brasil
My E.-mails are
marciolf
marcio_co
codivina

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20010402/50c6886d/attachment.html>

Reply | Threaded
Open this post in threaded view
|

Help-me

Raimo Niskanen-3
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.

... and semaphores do not exist either, since Erlang uses asynchronous
message passing between processes, and the processes can (almost) only
interact through this message passing. Therefore processes have no
common data and do not need semaphores to synchronize updates of common
data areas. Exception: ETS tables can be common to several processes and
updates might need to be synchronized. This is often solved by feeding
all updates (using message passing) through one process - eliminating
collisions.

If you really need a semaphore to control the access of e.g some
external resource, one can easily be written as a locker process that
holds the semaphore state and is accessed through message passing, or,
again, have one single process that controls the external resource.

I hope this information gives some clarity to you.

/ Raimo Niskanen, Ericsson UAB, Erlang/OTP



> Col?gio Divina Provid?ncia wrote:
>
>     Dear Srs.
>      Please, I'm a graduate student of Computer Cienci in
> State of Santa Catarina Brazil, I need developer a Work of
> Erlang Language.
>     Wel,  I like know who I do array in Erlang?
>     and I need developer a work of producer and consumer whit erlang
> using semaphores
>     Please Reply me  and help-me..
>
>
>     Thangs ...
>
> Marcio Luiz Ferreira
> Studant of Computing Cience of University of FURB
> Fundation University Regionary of Blumeau  SC - Brasil
> My E.-mails are
> marciolf
> marcio_co
> codivina
>


Reply | Threaded
Open this post in threaded view
|

Help-me

Ulf Wiger-4
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



Reply | Threaded
Open this post in threaded view
|

Help-me

Robert Virding-4
Ulf Wiger <etxuwig> writes:

>On Tue, 3 Apr 2001, Raimo Niskanen wrote:
>
>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.

The standard dict module in stdlib will do the same thing as dynarray
and it has the added benefit that not only does it expand on demand it
will also compact when it can.

        Robert