Re: RE: 3 dimension array

new topic     » goto parent     » topic index » view thread      » older message » newer message

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.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu