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

Username:   Password: 
 RegisterRegister   
 init commands for multidimensional arrays
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Lucas




PostPosted: Sun Apr 03, 2011 6:49 pm   Post subject: init commands for multidimensional arrays

What is it you are trying to achieve?
Just trying to use an "init" command for multidimensional arrays to save space, cant figure how to do it though. is it doable?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Apr 03, 2011 7:16 pm   Post subject: RE:init commands for multidimensional arrays

Turing Docs to the rescue! init
code:

var names : array 1 .. 2, 1 .. 3 of string :=
            init ( "Tom", "Dick", "Harry",
                 "Alice", "Barbara", "Cathy")
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Raknarg




PostPosted: Mon Apr 04, 2011 8:20 am   Post subject: RE:init commands for multidimensional arrays

Its the same as a regular array, you input initial values for the amount of elements you have.
Lucas




PostPosted: Mon Apr 04, 2011 6:10 pm   Post subject: RE:init commands for multidimensional arrays

aha k thx, thats what i had though but when i tried it it didn,t work, wrong variable type because i had declared my variables as
var names : array 1 .. 2 of array 1 .. 3 of string :=
init ( "Tom", "Dick", "Harry",
"Alice", "Barbara", "Cathy")
Raknarg




PostPosted: Mon Apr 04, 2011 7:46 pm   Post subject: RE:init commands for multidimensional arrays

Yeah, remember when we were looking at my program, you suggested using multi d arrays? Remember how it didn't work because you needed a comma? Razz
Tony




PostPosted: Mon Apr 04, 2011 7:54 pm   Post subject: RE:init commands for multidimensional arrays

both are valid, but work subtly differently, and require different syntax
code:

var foo : array 1..1, 1..1 of int
foo(1,1)

vs
code:

var foo : array 1..1 of array 1..1 of int
foo(1)(1)

The latter doesn't get the benefit of init, but you could select an entire row at a time; foo(1) has "array of int" type.

Edit: not sure about the validity of those indices.
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: