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.
STRUCT(INT i,[3]REAL r)sexplain why parentheses are needed in the phrase
(r OF s)[2]Ans
[3]STRUCT(INT i,REAL r)sexplain why parentheses are not needed in the phrase
r OF s[2]
. AnsMODE 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
p OF s1
p OF s2
(n OF s1)[2:]