|
|||||
|
|||||
Prerequisite Concepts | Related Topics | ||||
Records, pre-defining |
A record type may be declared elsewhere
.
declare record point elsewhere
The elsewhere declaration does not create a record type. The full record declaration must be given before variables of the record type are declared. However, the elsewhere declaration makes the type name available for use in other record type declarations. This allows you to create recursive record types:
declare record bar elsewhere declare record foo field integer a field bar x variable declare record bar field integer b field foo y
In this example, foo and bar are both record types. Foo has a field of type bar and bar has a field of type foo. This is perfectly legal and potentially useful. Notice however, that at least one of the fields of the mutually referenced types need to be declared variable. If not, each new foo
creates a new bar
and each new bar
creates a new foo
, to infinity. Circular data structures are permitted. However, it is your responsibility to see that they are properly bounded.
You can also create a record type which has a field of is own type. This is particularly useful if you want to create a tree:
declare record node field stream name field node children variable
Records which have been declared elsewhere can be extended, but the extended types must also be declared elsewhere:
declare record point elsewhere declare record pixel extends point elsewhere
This exposes the relationship between pixels and points without defining their fields. (The fields will need to be defined before either type can be used. The fields for the point record must be defined before those of pixel.)
Prerequisite Concepts
|
Related Topics
|
Copyright © Stilo International plc, 1988-2010.