Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.

9.5.6 Typed lists

Normal lists contain LONG elements, so you can write initialised arrays of LONG elements. 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 CHAR, INT, 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

It is equivalent to:

  DEF ints[4]:ARRAY OF INT, objects[2]:ARRAY OF rec, p:PTR TO CHAR

The last group of assignments to objects[1] 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.