[erlang-questions] Clueless am I

Stefan Schmiedl s@REDACTED
Mon Apr 25 21:29:46 CEST 2016


Hi Don,

these are not the arrays you're looking for.

http://erlang.org/doc/man/array.html starts with "Functional, extendible
arrays".
A bit further down you can find "The representation is not documented and is
subject to change without notice."

So the array datatype is not the contiguous block of memory you are used to,
but a functional data structure. This means that an array, is basically
read-only.

Mathematical functions are reproducible: You pass in the same arguments, you
get
the same result. So the array A1 in your non-working example references the
original
datastructure and your code is equivalent to

>      A1 = array:set(0, nextevent(), array:new(20)),
>      A2 = array:set(1, nextevent(), A1),
>      A3 = array:set(2, nextevent(), A1),
>      A4 = array:set(3, nextevent(), A1),
>      A5 = array:set(4, nextevent(), A1),

s.

> -----Ursprüngliche Nachricht-----
> Von: erlang-questions-bounces@REDACTED [mailto:erlang-questions-
> bounces@REDACTED] Im Auftrag von Donald Steven
> Gesendet: Montag, 25. April 2016 21:16
> An: erlang-questions@REDACTED
> Betreff: [erlang-questions] Clueless am I
> 
> Dear friends,
> 
> Please forgive me for being clueless.  (I'm sure it's because I come to
Erlang
> steeped in C.) 

Yes. SCNR.

 Below are 2 very simple programs.  Both run: the first one
> works (but requires all these variables which are meaningless for my
> purposes) but the second one  does not set the array values and I don't
> understand why not or how to do this.
> 
> Thank for any help you can provide.
> 
> Don
> 
> %% THIS WORKS
> 
> -module(arraytest).
> -export([main/0]).
> 
> main() ->
> 
>      A1 = array:set(0, nextevent(), array:new(20)),
>      A2 = array:set(1, nextevent(), A1),
>      A3 = array:set(2, nextevent(), A2),
>      A4 = array:set(3, nextevent(), A3),
>      A5 = array:set(4, nextevent(), A4),
> 
>      io:format("~nArray: ~p~n", [A5]),
>      io:format("Array size: ~p~n~n", [array:size(A5)]).
> 
> nextevent() ->
> 
>      [rand:uniform()].
> 
> ============================================
> 
> %% THIS DOES NOT WORK
> 
> -module(arraytest).
> -export([main/0]).
> 
> main() ->
> 
>      A1 = array:set(0, nextevent(), array:new(20)),
>      array:set(1, nextevent(), A1),
>      array:set(2, nextevent(), A1),
>      array:set(3, nextevent(), A1),
>      array:set(4, nextevent(), A1),
> 
>      io:format("~nArray: ~p~n", [A1]),
>      io:format("Array size: ~p~n~n", [array:size(A1)]).
> 
> nextevent() ->
> 
>      [rand:uniform()].
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list