Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Obtain Upper Bounds of Multi-dimensional Array
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
vahnx




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: 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.
vahnx




PostPosted: 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
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
trishume




PostPosted: 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
Tony




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

could always just check the docs upper
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: