procedure T(U,V,X,Y:integer); var A:record A,B:integer end; B:record B,A:integer end; begin with A do begin A:=4; B:=V end; with B do begin A:=X; B:=Y end end. Identify the declarations bound to each A and B occurrence.
Answer & solution
Answer: First with assigns A.A=4 and A.B=V; second assigns B.A=X and B.B=Y. (no official key was published)
There are six distinct declarations with these spellings: two outer record variables, outer A and outer B, and two integer fields inside each record. A field name belongs to its record’s field namespace; declaring field A does not replace the surrounding record variable A.
In “with A do”, the selector A is resolved before entering the with environment, so it denotes the outer record variable A. Within that body, unqualified field identifiers take precedence: the assignment A:=4 means outer-A.A:=4, while B:=V means outer-A.B:=V. V remains the procedure parameter.
That with scope ends at its end. Therefore the selector in the following “with B do” denotes the outer record B, not the field B from the preceding block. Within the second body, A:=X means outer-B.A:=X and B:=Y means outer-B.B:=Y. X and Y are parameters. The field declarations in the first record define A.A and A.B; those in the second define B.B and B.A. Parameter U is unused in the displayed the paper.
Original paper, page 6