Normal lists contain
LONG elements, so you can write initialised arrays of
What about other kinds of array?
Well, that's what typed lists are for.
You specify the type of the elements of a list using `:type' after the closing `]'.
The allowable types are
LONG and any object type.
There is a subtle difference between a normal,
LONG list and a typed list (even a
LONG typed list): only normal lists can be used with the list functions (see 9.5.4 List functions).
For this reason, the term `list' tends to refer only to normal lists.
The following code fragment uses the object
rec defined earlier (see 9.4.1 Example object) and gives a couple of examples of typed lists:
DEF ints:PTR TO INT, objects:PTR TO rec, p:PTR TO CHAR ints:=[1,2,3,4]:INT p:='fred' objects:=[1,2,p,4, 300,301,'barney',303]:rec
It is equivalent to:
DEF ints:ARRAY OF INT, objects:ARRAY OF rec, p:PTR TO CHAR ints:=1 ints:=2 ints:=3 ints:=4 p:='fred' objects.tag:=1 objects.check:=2 objects.table:=p objects.data:=4 objects.table:='barney' objects.tag:=300 objects.data:=303 objects.check:=301
The last group of assignments to
objects have deliberately been shuffled in order to emphasise that the order of the elements in the definition of the object
rec is significant.
Each of the elements of the list corresponds to an element in the object, and the order of elements in the list corresponds to the order in the object definition.
In the example, the (object) list assignment line was broken after the end of the first object (the fourth element) to make it a bit more readable.
The last object in the list need not be completely defined, so, for instance, the second line of the assignment could have contained only three elements. This makes an object-typed list slightly different from the corresponding array of objects, since an array always defines a whole number of objects. With an object-typed list you must be careful not to access the undefined elements of a partially defined, trailing object.
Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.