I have an Erlang project requiring generating a nested list of array indices. Perhaps using arrays: would be a quick solution, but I would like to see how this is done without that module.
If one knows the number of dimensions of an array, creating a nested list of array indices can be done in one line eg.
array2Dim(M,N) -> [[[X,Y] || X <- lists:seq(1,N)] || Y <- lists:seq(1,M)].
I've been struggling to implement a function, say arrayNDim/1 that will take a list [D1,D2,..., Dn] of unknown length containing dimensions to generate the indices of the D1 x D2 x...,Dn array.
I have thought about spawning processes as a 'gear train' to produce the structure but I suspect the solution might be much simpler.