[erlang-questions] Clueless am I

Donald Steven <>
Mon Apr 25 21:15:56 CEST 2016


Dear friends,

Please forgive me for being clueless.  (I'm sure it's because I come to 
Erlang steeped in C.)  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()].



More information about the erlang-questions mailing list