[erlang-questions] 2D Map Arrays

Richard Carlsson <>
Mon Sep 11 22:34:54 CEST 2006

Jeff Crane wrote:
> I dont see it.
> ...   
> [?_assertMatch(#array{size=0,max=N0,default=undefined,elements=N0},
> 		   new(0)),

Ignore the #array stuff - that's just checking that the
internal representation is ok.

>      ?_assert(new() == new(0)),

This checks that calling new() is the same thing as calling new(0).

>      ?_assert(0 == array:size(new())),

This checks that the size of an array created with new() is zero.

>      ?_assert(17 == array:size(new(17))),

This checks that if you ask for a new array with 17 elements,
the size is indeed 17. Et cetera, et cetera.

But there are also tests that check, for instance, that if you do
'set(N, X, new())', you will get an array with N+1 elements (from
0 to N) as a result. I thought those might help you.

>>> Does it dynamically resize?
>> Yes.
> test() ->
> 	MyNewArr = array:new(0,0),
> 	MyBiggerArr = array:set(1,4,MyNewArr),
> 	array:size(MyBiggerArr).
> That's an example I can understand. Arrays are
> identified by the tuples returned from array:new

Yes. Erlang has no way to hide how the representation really looks
(that is, it has no truly abstract data types), but by convention,
if the representation isn't documented, you should never assume
that it will stay the same, and you should only use the functions
to access the data structure.

> you cannot reassign variables so this requires
> reassignment to new Atoms as the array is processed.

Just don't confuse variables with atoms. Erlang has single-assignment
variables, yes, so you must use another variable name for the new array
after each "update" (well, at least within the same function clause).
Atoms, however, are data objects, similar to strings.

> Yes, I'm not amazingly good at learning how to read
> and use erlang modules, but I am happy to be the
> newbie filter. 

I confess that my "preview" of the array module was mostly aimed
at seasoned Erlang programmers, who already are very familiar with
the similar standard library modules 'dict', 'gb_trees', and 'ets'.
Well, hang in there, and you too will soon be a seasoned functional
programmer. (Cue the currying jokes!)


More information about the erlang-questions mailing list