Properties
A Property behaves in a very similar way to an ordinary APL variable. To obtain the value of a Property, you simply reference its name. To change the value of a Property, you assign a new value to the name.
However, under the covers, a Property is accessed via a PropertyGet function and its value is changed via a PropertySet function. Furthermore, Properties may be defined to allow partial (indexed) retrieval and assignment to occur.
There are three types of Property, namely Simple, Numbered and Keyed.
- A Simple Property is one whose value is accessed (by APL) in its entirety and re-assigned (by APL) in its entirety.
- A Numbered Property behaves like an array (conceptually a vector) which is only ever partially accessed and set (one element at a time) via indices. The Numbered Property is designed to allow APL to perform selections and structural operations on the Property.
- A Keyed Property is similar to a Numbered Property except that its elements are accessed via arbitrary keys instead of indices.
The following cases illustrate the difference between Simple and Numbered Properties.
If Instance MyInst has a Simple Property Sprop and a Numbered Property Nprop, the expressions
X←MyInst.SProp
X←MyInst.SProp[2]
both cause APL to call the PropertyGet function to retrieve the entire value of Sprop. The second statement subsequently uses indexing to extract just the second element of the value.
Whereas, the expression:
X←MyInst.NProp[2]
causes APL to call the PropertyGet function with an additional argument which specifies that only the second element of the Property is required. Moreover, the expression:
X←MyInst.NProp
causes APL to call the PropertyGet function successively, for every element of the Property.
A Property is defined by a :Property ... :EndProperty section in a Class Script.
Within the body of a Property Section there may be:
- one or more
:Accessstatements which must appear first in the body of the Property. - a single PropertyGet function.
- a single PropertySet function
- a single PropertyShape function