Structures or user-defined types (UDT's) are well-known in many programming languages and during this stage, support for structures has been revised (see stages 94-95). While at it, a table type was also added. Think of tables as an in-between type: they are more flexible than records, more limited than structures with regards to field type support, but with one major advantage: their fields can be referenced by index, which gives them kind of enumeration functionality:
Code: Select all
table ttest is
id : int;
title : str;
buffer : byte * 16;
last : bool;
end
decl sub table_test();
main do
table_test();
end
sub table_test()
dim test: ttest;
dim i: itr;
do
with test do
.id = 1;
print(.id);
.title = "This is a table.";
print(.title);
' fld() returns a table field's index
for i = 0 to fld(.last) :++ do
if i == fld(.title) do
print("title is field #:");
end
print(i+1);
end
end
end
It is also possible to define a table of constants:
Code: Select all
const table messages is
msg1 = "first message";
msg2 = "second message";
msg3 = "third message";
end
dim msg: messages;
dim num: uint;
main do
num = 2;
' by message number (zero-based)
print(msg[num]);
' by message name
print(msg.msg3);
end
To be continued...