This section describes how you can add new ``in parent attributes''
(see Constructing Subdomains and Parents in the Reference Manual).
As an example, we describe how Index and its related functions
are implemented.
There are a function Index, an operation IndexOp, and an attribute
IndexInParent.
They are created together as shown below,
and after they have been created,
methods need be installed only for IndexOp.
In the creation process, IndexInParent already gets one default method
installed
(in addition to the usual system getter of each attribute,
see Attributes in the Reference Manual),
namely D -> IndexOp( Parent( D ), D ).
The function Index takes any number of arguments and proceeds as
follows.
HasParent( sub ) and IsIdenticalObj( super, Parent( sub ) ),
the tester HasIndexInParent( sub ) is consulted.
true, IndexInParent( sub ) is called
(which will then hopefully choose the system getter of the attribute)
and the result returned.
false, IndexOp is called in the obvious way
and the result is passed to the setter SetIndexInParent (which will
hopefully store it). The result is also returned.
IndexOp is called with the same arguments that Index was
called with, and the result is returned.
(Note that it is in principle possible to install even IndexOp methods
for a number of arguments different from two, with InstallOtherMethod,
see Creating Attributes and Properties in ``Programming in GAP'').
InParentFOA( name, super-req, sub-req, NewAttribute )
InParentFOA( name, super-req, sub-req, NewProperty )
declares function, operation, and attribute as described above,
with names name, nameOp, and nameInParent.
super-req and sub-req specify the required filters for the first and
second argument of the operation nameOp,
which are needed to create this operation with NewOperation
(see NewOperation).
sub-req is also the required filter for the corresponding attribute
nameInParent;
note that HasParent is not required for the argument U of
nameInParent, because even without a parent stored,
Parent( U ) is legal, meaning U itself
(see Parents in the Reference Manual).
The fourth argument is NewProperty if nameInParent takes only
boolean values (for example in the case IsNormalInParent),
and NewAttribute otherwise.
For example, to set up the three objects Index, IndexOp,
and IndexInParent together,
the declaration file ``lib/domain.gd'' contains the following line of code.
InParentFOA( "Index", IsGroup, IsGroup, NewAttribute );
Note that no methods can/need be installed for Index and
IndexInParent.
[Top] [Previous] [Up] [Next] [Index]
GAP 4 manual