init commands for multidimensional arrays
Author |
Message |
Lucas
![](http://compsci.ca/v3/uploads/user_avatars/11933987244d8a65c6dbba2.png)
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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")
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Lucas
![](http://compsci.ca/v3/uploads/user_avatars/11933987244d8a65c6dbba2.png)
|
Posted: 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") |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: 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 Razz](http://compsci.ca/v3/images/smiles/icon_razz.gif) |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
|
|