
-----------------------------------
Lucas
Sun Apr 03, 2011 6:49 pm

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?

-----------------------------------
Tony
Sun Apr 03, 2011 7:16 pm

RE:init commands for multidimensional arrays
-----------------------------------
Turing Docs to the rescue! [tdoc]init[/tdoc]
[code]
var names : array 1 .. 2, 1 .. 3 of string :=
            init ( "Tom", "Dick", "Harry",
                 "Alice", "Barbara", "Cathy")
[/code]

-----------------------------------
Raknarg
Mon Apr 04, 2011 8:20 am

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
Mon Apr 04, 2011 6:10 pm

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
Mon Apr 04, 2011 7:46 pm

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? :P

-----------------------------------
Tony
Mon Apr 04, 2011 7:54 pm

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)
[/code]
vs
[code]
var foo : array 1..1 of array 1..1 of int
foo(1)(1)
[/code]
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.
