Subsections

Summary

This chapter has significantly increased the number of different modes we can construct. Structures are constructed using the mode constructor STRUCT. Complicated structures are best declared using the mode declaration (using MODE). Structures can have any number of fields from one up, and the fields can have any mode, including the same modes. The mode COMPL has been declared in the standard prelude together with the necessary operators to manipulate complex numbers.

Structures can contain procedures and multiples and multiples of structures can be declared. Although structures containing reference modes can be declared, they are covered in chapter 11. Operators and procedures which have structure parameters or yield can be declared.

Here are some exercises to check what you have learned.


Exercises

7.14
Write a suitable mode for a football team which contains the names of its 11 members, the name of the team (ordinary name, not the Algol 68 meaning), the number of games played, won and drawn, and the number of goals scored for and against. Ans[*]
7.15
Given the declaration
   STRUCT(INT i,[3]REAL r)s
explain why parentheses are needed in the phrase
   (r OF s)[2]
Ans[*]
7.16
Given the declaration
   [3]STRUCT(INT i,REAL r)s
explain why parentheses are not needed in the phrase r OF s[2]. Ans[*]
7.17
Given the declarations
   MODE S2,
        S1 = STRUCT([3]CHAR n,
                    PROC S2 p),
        S2 = STRUCT([3]CHAR m,
                    PROC(S1)S2 p);
   S1 s1;  S2 s2;
what are the modes of each of the following: Ans[*]
(a)
p OF s1

(b)
p OF s2

(c)
(n OF s1)[2:]


Sian Mountbatten 2012-01-19