
-----------------------------------
Zampano
Wed Jan 30, 2008 3:57 pm

Syntax for Resizing a Multi-Dimensional Array
-----------------------------------
I've been unable to increase the size of an array because Turing Help does not show examples of the syntax for the new command when the array has more than one dimension.
With count indicating the new upper, and balls as the array, I've tried:

new balls(1), count
new balls, 1, count
new balls, count, 1

The first gave me a too few parameters error, while the compiler apologized to me for the absence of resizing dimensions other than the first.
Can any one show the syntax for accomplishing this particular task?

-----------------------------------
Saad
Wed Jan 30, 2008 4:07 pm

RE:Syntax for Resizing a Multi-Dimensional Array
-----------------------------------
You can't resize multi-dimensional flexibles arrays using the standard way, what you can do is create a flexible array class and have a flexible array of flexible arrays classes.

-----------------------------------
Zampano
Wed Jan 30, 2008 4:24 pm

Re: Syntax for Resizing a Multi-Dimensional Array
-----------------------------------
I think you've misunderstood me.
I don't want to resize more than one dimension. The problem is that I don't know the syntax to access that particular dimension of the array.
That being said, I guess I could start using records instead. Thanks.

-----------------------------------
Saad
Wed Jan 30, 2008 5:04 pm

RE:Syntax for Resizing a Multi-Dimensional Array
-----------------------------------
Thats what I mean, you cant access a single dimension in a multi-dimensional array for resizing

-----------------------------------
Zampano
Wed Jan 30, 2008 5:48 pm

Re: Syntax for Resizing a Multi-Dimensional Array
-----------------------------------
In the current implementation (1999), with a multi-dimensional array with a non-zero number of total elements, it is a run-time error to change any but the first dimension (unless one of the new upper bounds is one less than the corresponding lower bound, giving 0 elements in the array) as the algorithm to rearrange the element memory locations has not yet been implemented.
I don't mean to bother, but they affirm that it does indeed work, and as you say you can't access a specific dimension in Turing with new, why wouldn't the first instance of new that I tried not work?

-----------------------------------
Saad
Wed Jan 30, 2008 6:11 pm

RE:Syntax for Resizing a Multi-Dimensional Array
-----------------------------------
Ah, In that case its new , new size for the first dimension, followed by original size of the other dimensions
 
A code example

var foo : flexible array 1 .. 3, 1 .. 2 of int
for i : 1 .. 3
    for j : 1 .. 2
        foo (i, j) := i
    end for
end for
new foo, 2, 2  %% Now we have a 2 elements in the first dimension
for i : 1 .. 2
    for j : 1 .. 2
        put foo (i, j)
    end for
end for

for i : 1 .. 3 %% This is an error since our size is 2 not 3
    for j : 1 .. 2
        put foo (i, j)
    end for
end for

