2.6 Immediate Methods

Usually a method is called only if its operation has been called and if this method has been selected.

For attributes and properties, one can install also immediate methods. An immediate method is called automatically as soon as it is applicable to an object, provided that the value is not yet known. Afterwards the attribute setter is called in order to store the value.

Note that in such a case GAP executes a computation for which it was not explicitly asked by the user. So one should install only those methods as immediate methods that are extremely cheap. To emphasize this, immediate methods are also called zero cost methods. The time for their execution should really be approximately zero.

An immediate method method for the attribute or property attr with requirement req is installed via

  • InstallImmediateMethod( attr, req, val, method )

    where val is an integer value that measures the priority of method among the immediate methods for attr.

    Note the difference to InstallMethod that no family predicate occurs because attr expects only one argument, and that req is not a list of requirements but the argument requirement itself.

    For example, the size of a permutation group can be computed very cheaply if a stabilizer chain of the group is known. So it is reasonable to install an immediate method for Size with requirement IsGroup and Tester( stab ), where stab is the attribute corresponding to the stabilizer chain.

    Another example would be the implementation of the conclusion that every finite group of prime power order is nilpotent. This could be done by installing an immediate method for the attribute IsNilpotentGroup with requirement IsGroup and Tester( Size ). This method would then check whether the size is a finite prime power, return true in this case and otherwise call TryNextMethod(). But this requires factoring of an integer, which cannot be guaranteed to be very cheap, so one should not install this method as an immediate method.

    Immediate methods are thought of as a possibility for objects to gain useful knowledge. They must not be used to force the storing of ``defining information'' in an object. In other words, GAP should work even if all immediate methods are invalidated.

    [Top] [Previous] [Up] [Next] [Index]

    GAP 4 manual
    February 2000