Re: 3 dimension array
- Posted by Juergen Luethje <jluethje at gmx.de> Aug 21, 2002
- 394 views
C. <cklester at yahoo.com> wrote: >> >> a = 3 >> >> b = 7 >> >> c = 4 >> >> somearray = repeat(repeat(repeat(0,c),b),a) >> >> > This will need to be made into a recursive function, I'm sure... :) >> >> The example I gave works. Why "need to"? > In case he wants more than 3 dimensions (as he mentioned in his original > post)... I disagree for several reasons. 1) With the same method I used (_without_ recursion), you can create arrays with say 100 dimensions if you like, just by nesting repeat() 100 times, instead of 3 times. 2) It's not a matter of the number of dimensions one wants, the main question is, if a) the number of dimensions is known at "compile" time (then a "static" approach like mine will be OK for any number of dimensions), or b) if the number of dimensions is dynamically provided at runtime. 3) For case 2b), my approach does not work, but he didn't describe that situation in his question. And even in case 2b), recursion is not needed, simple iteration will be sufficient to dimension the array: --==--==--==--==--==--==--==--==--==--==--==--==--== sequence dim object somearray dim = {3,7,4} -- number and size of dimensions somearray = 0 for d = length(dim) to 1 by -1 do somearray = repeat(somearray, dim[d]) end for -- etc. --==--==--==--==--==--==--==--==--==--==--==--==--== Regards, Juergen