4.2 Dispatchers

In the previous section it was mentioned that domains are represented by domain records, and that each domain record has an operations record. This operations record is used by functions like Size to find out how to compute this information for the domain. Let us discuss this mechanism using the example of Size. Suppose you call Size with a domain D.

First Size tests whether D has a component called size, i.e., if D.size is bound. If it is, Size assumes that it holds the size of the domain and returns this value.

Let us suppose that this component has no assigned value. Then Size looks at the component D.operations, which must be a record. Size takes component D.operations.Size of this record, which must be a function. Size calls this function passing D as argument. If a domain record has no Size function in its operations record, an error is signalled.

Finally Size stores the value returned by D.operations.Size( D ) in the component D.size, where it is available for the next call of Size( D ).

Because functions like Size do little except dispatch to the function in the operations record they are called dispatcher functions.

Which function is called through this mechanism obviously depends on the domain and its operations record. In principle each domain could have its own Size function. In practice however this is not the case. For example all permutation groups share the operations record PermGroupOps so they all use the same Size function PermGroupOps.Size.

Note that in fact domains of the same type not only share the functions, in fact they share the operations record. So for example all permutation groups have the same operations record. This means that changing such a function for a domain D in the following way D.operations.function := new-function; will also change this function for all domains of the same type, even those that do not yet exist at the moment of the assignment and will only be constructed later. This is usually not desirable, since supposedly new-function uses some special properties of the domain D to work efficiently. We suggest therefore, that you use the following assignments instead:
D.operations := Copy( D.operations );
D.operations.function := new-function;.

Some domains do not provide a special Size function, either because no efficient method is known or because the author that implemented the domain simply was too lazy to write one. In those cases the domain inherits the default function, which is DomainOps.Size. Such inheritance is uncommon for the Size function, but rather common for the Union function.

Previous Up Top Next
Index

GAP 3.4.4
April 1997