Computer Science Canada

Syntax for Resizing a Multi-Dimensional Array

Author:  Zampano [ Wed Jan 30, 2008 3:57 pm ]
Post subject:  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:

code:
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?

Author:  Saad [ Wed Jan 30, 2008 4:07 pm ]
Post subject:  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.

Author:  Zampano [ Wed Jan 30, 2008 4:24 pm ]
Post subject:  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.

Author:  Saad [ Wed Jan 30, 2008 5:04 pm ]
Post subject:  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

Author:  Zampano [ Wed Jan 30, 2008 5:48 pm ]
Post subject:  Re: Syntax for Resizing a Multi-Dimensional Array

Turing Help on Arrays wrote:
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?

Author:  Saad [ Wed Jan 30, 2008 6:11 pm ]
Post subject:  RE:Syntax for Resizing a Multi-Dimensional Array

Ah, In that case its new <array name>, new size for the first dimension, followed by original size of the other dimensions

A code example
Turing:

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


: