1. RE: 3 dimension array
- Posted by darceman <darce at ffi.com> Aug 21, 2002
- 357 views
This is such a great forum. Many thanks for the prompt replies. I believe that the below example creates an equivalent to DIM somearray(3,7,4). No need to reply unless I am wrong. I know I have to break from the shackles of BASIC but during the transition the analogy to the mindset of BASIC will help me. C. K. Lester 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)... > >
2. Re: RE: 3 dimension array
- Posted by Derek Parnell <ddparnell at bigpond.com> Aug 21, 2002
- 375 views
22/08/2002 8:43:53 AM, darceman <darce at ffi.com> wrote: > >This is such a great forum. Many thanks for the prompt replies. It is, isn't it. >I believe that the below example creates an equivalent to DIM >somearray(3,7,4). No need to reply unless I am wrong. I know I have to >break from the shackles of BASIC but during the transition the analogy >to the mindset of BASIC will help me. > One huge difference between BASIC and Euphoria is that in Euphoria all arrays are dynamic. In that the number of dimensions can be changed at will through out the life of the array. Here is one attempt at a function that emulates BASIC's DIM array command. function DIMArray( sequence Dimension, object InitValue ) sequence lNewArray if length(Dimension) = 0 then return 0 end if lNewArray = InitValue for i = length(Dimension) to 1 by -1 do if integer(Dimension[i]) then lNewArray = repeat(lNewArray, Dimension[i]) else return i end if end for return lNewArray end function It can be used like this: object Space3D Space3D = DIMArray( {3, 7, 4}, 0) if integer(Space3D) then ErrAbort(sprintf("All dimensions must be integers; dimension %d is not.", Space3D)) end if Then elements can be reference like: Space3D[1][1][1] = 2 Space3D[2][3][1] = "Euphoria rocks!" ------------ cheers, Derek.
3. RE: 3 dimension array
- Posted by "C. K. Lester" <cklester at yahoo.com> Aug 21, 2002
- 415 views
> > 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. I agree. But I'm always looking for the lazy way out... and if circumstances or requirements "might" change in the future, I like to plan for that at the outset. > 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) 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: Agreed... I should have said "recursion or iteration." :)