Contents | Prev | Next | Index
The purpose of a with statement is to execute a statement sequence depending on the result of a type test. The with statement applies a type guard to every occurence of the tested variable within this statement sequence. Notice that within this statement sequence the qualification of record field identifiers may not be omitted. The Oberon-2 with statement is different from the one in Pascal or Modula-2. It is more like a global guard statement.
guard_stmt ::= first_guard guard_list default_guard
END first_guard ::= WITH rec_designator DO stmt_seq rec_designator ::= qualident : qualident guard_list ::= guard_list next_guard ::= <empty> next_guard ::= | rec_designator DO stmt_seq default_guard ::= ELSE stmt_seq ::= <empty> |
If v is a variable parameter of record type or a pointer variable, and if it is of a static type T0, the statement
WITH v:T1 DO S1
| v:T2 DO S2
ELSE S3
END
has the following meaning: if the dynamic type of v is T1 then execute statement sequence S1, where v is regarded as if it had the static type T1; else if the dynamic type of v is T2, then execute statement sequence S2, where v is regarded as if it had the static type T2; else S3 is executed. T1 and T2 must be extensions of T0. If no type test is satisfied and if there is no else clause for the with statement, the program is aborted.
Example:
WITH t:CenterTree DO i:=t.width; c:=t.subnode END
Contents | Prev | Next | Index
Canterbury Oberon-2 for Java (Last documentation update
Feb 8, 2000)
Copyright © 1998 Mill Hill &
Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to
mhc@webcom.com