|
By Andrew J. Wozniewicz
Milwaukee, August 3, 2008
Note: Associative arrays will be supported in WANT 2.0.4 as System.Dictionary objects.
As such, they will differ in syntax and usage from what was described below. Please, refer to the
more up-to-date article, to be published shortly.
The next alpha release of WANT will include rudimentary support for
associative arrays. Below is a sample WANTScript application that makes use
of these. Notice how you can use array subscripts of different types. The
array declaration does not contain anything between the square brackets.
project Test061
var A[]
A[0] := "ZERO"
WriteLn(A[0]);
A[1] := A[0];
WriteLn(A[1]);
A[1] := 1;
WriteLn(A[1]);
A[2] := True;
WriteLn(A[2]);
A[0.5] := "Half"
WriteLn(A[0.5]);
A[0.25] := "Quarter"
WriteLn(A[0.5]);
A["Hello"] := "Hello world!"
WriteLn(A["Hello"]);
A["Bye"] := "Goodbye world!"
WriteLn(A["Bye"]);
A[True] := 1
A[False] := 0
WriteLn(A[True]);
WriteLn(A[False]);
A["Bye"] := A[True]
WriteLn(A["Bye"]);
end
Here is the output:
WANT 2.0.2 (Build 2008.08.03.21.44)
D:\Projects\Delphi7\WANT2\Scripts\test061.want
ZERO
ZERO
1
-1
Half
Half
Hello world!
Goodbye world!
1
0
1
172 tokens, 41 lines, 1 file
0 errors, 0 warnings, 0 hints
0 seconds
-Andrew
|