Computer Science Canada

Obtain Upper Bounds of Multi-dimensional Array

Author:  vahnx [ Fri Feb 24, 2012 11:33 am ]
Post subject:  Obtain Upper Bounds of Multi-dimensional Array

What is it you are trying to achieve?
Obtain the upper bounds of each dimension of an array.


What is the problem you are having?
Upper bound only returns first dimension.


Describe what you have tried to solve this problem
Tried using a complex 1D array with each string entry delimited by commas.
Praying to Allah.
Watched Dexter.
Gave up and put fixed sizes.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing:

const numOfShortcuts := 6    % Must get rid of and auto determine size,
const numOfOptions := 3       % array 1 .. *, 1 .. * not working
var shortcut : array 1 .. numOfShortcuts, 1 .. numOfOptions of string := init (
    "North", "nor", "n",
    "West", "wes", "w",
    "East", "eas", "e",
    "South", "sou", "s",
    "Open barn door", "open", "o",
    "Scream loudly", "scream", "s"
    )


Please specify what version of Turing you are using
4.1

Author:  Insectoid [ Fri Feb 24, 2012 11:44 am ]
Post subject:  RE:Obtain Upper Bounds of Multi-dimensional Array

A 2D array is an array of arrays. upper(array) gives the size of the first dimension. upper(array(1)) will give the size of the array contained in the first cell of the 1st dimension.

Author:  vahnx [ Fri Feb 24, 2012 2:53 pm ]
Post subject:  RE:Obtain Upper Bounds of Multi-dimensional Array

I tried that and get "Too few subscripts".
If I do put upper(array(1,1)) I get 255 :S

Author:  Tony [ Fri Feb 24, 2012 3:45 pm ]
Post subject:  RE:Obtain Upper Bounds of Multi-dimensional Array

@Insectoid -- you are thinking of
code:

var foo : array 1..n of array 1..k of string


@vahnx -- (1,1) is a single element. A String "North", in specific.

Author:  trishume [ Fri Feb 24, 2012 4:08 pm ]
Post subject:  Re: Obtain Upper Bounds of Multi-dimensional Array

I think the correct syntax is upper(array, dimension).

For example upper(shortcut,2) should return numOfOptions

Author:  Tony [ Fri Feb 24, 2012 5:23 pm ]
Post subject:  RE:Obtain Upper Bounds of Multi-dimensional Array

could always just check the docs upper


: