For every attribute two further operations, the attribute setter and the attribute tester are defined.
To check whether an object belongs to an attribute attr, the tester
Tester( attr ) O
of the attribute is used;
this is a filter (see Filters) that returns true or false,
depending on whether or not the value of attr for the object is known.
For example, Tester( Size )( obj ) is true if the size of the object
obj is known.
To store a value for the attribute attr in an object, the setter
Setter( attr ) O
of the attribute is used.
The setter is called automatically when the attribute value has been
computed for the first time.
One can also call the setter explicitly,
for example, Setter( Size )( obj, val ) sets val as size of the
object obj if the size was not yet known.
For each attribute attr that is declared with DeclareAttribute
resp. DeclareProperty (see Global Variables in the Library in
``Programming in GAP''),
tester and setter are automatically made accessible by the names
Hasattr and Setattr, respectively.
For example, the tester for Size is called HasSize,
and the setter is called SetSize.
gap> g:=Group((1,2,3,4),(1,2));;Size(g); 24 gap> HasSize(g); true gap> SetSize(g,99); gap> Size(g); 24
For two properties prop1 and prop2,
the intersection prop1 and prop2 (see Filters) is again a property
for which a setter and a tester exist.
Setting the value of this intersection to true for a GAP object
means to set the values of prop1 and prop2 to true for this object.
gap> prop:= IsFinite and IsCommutative; <Operation "<<and-filter>>"> gap> g:= Group( (1,2,3), (4,5) );; gap> Tester( prop )( g ); false gap> Setter( prop )( g, true ); gap> Tester( prop )( g ); prop( g ); true true
It is not allowed to set the value of such an intersection to false
for an object.
gap> Setter( prop )( Rationals, false ); You cannot set an "and-filter" except to true not in any function Entering break read-eval-print loop, you can 'quit;' to quit to outer loop, or you can return true to set all components true, but you might really want to reset just one component to continue
AttributeValueNotSet( attr, obj ) F
If the value of the attribute attr is already stored for obj,
AttributeValueNotSet simply returns this value.
Otherwise the value of attr( obj ) is computed and returned
without storing it in obj.
This can be useful when ``large'' attribute values (such as element lists)
are needed only once and shall not be stored in the object.
gap> HasAsSSortedList(g); false gap> AttributeValueNotSet(AsSSortedList,g); [ (), (4,5), (1,2,3), (1,2,3)(4,5), (1,3,2), (1,3,2)(4,5) ] gap> HasAsSSortedList(g); false
The normal behaviour of attributes (when called with just one argument)
is that once a method has been selected and executed, and has returned a
value the setter of the attribute is called, to (possibly) store the
computed value. In special circumstances, this behaviour can be altered
dynamically on an attribute-by-attribute basis, using the functions
DisableAttributeValueStoring and EnableAttributeValueStoring.
In general, the code in the library assumes, for efficiency, but not for correctness, that attribute values will be stored (in suitable objects), so disabling storing may cause substantial computations to be repeated.
InfoAttributes V
This info class (together with InfoWarning) is used for messages about attribute storing being disabled (at level 2) or enabled (level 3). It may be used in the future for other messages concerning changes to attribute behaviour.
DisableAttributeValueStoring( attr ) F
'DisableAttributeValueStoring( attr )' disables the usual call of 'Setter( attr )' when a method for attr returns a value. In consequence the values will never be stored. attr must be an attribute and not a property.
EnableAttributeValueStoring( attr ) F
'EnableAttributeValueStoring( attr )' enables the usual call of 'Setter( attr )' when a method for attr returns a value. In consequence the values may be stored. This will usually have no effect unless 'DisableAttributeValueStoring' has previously been used for attr. attr must be an attribute and not a property.
gap> g := Group((1,2,3,4,5),(1,2,3)); Group([ (1,2,3,4,5), (1,2,3) ]) gap> KnownAttributesOfObject(g); [ "LargestMovedPoint", "GeneratorsOfMagmaWithInverses", "MultiplicativeNeutralElement" ] gap> SetInfoLevel(InfoAttributes,3); gap> DisableAttributeValueStoring(Size); #I Disabling value storing for Size gap> Size(g); 60 gap> KnownAttributesOfObject(g); [ "One", "LargestMovedPoint", "NrMovedPoints", "MovedPoints", "GeneratorsOfMagmaWithInverses", "MultiplicativeNeutralElement", "StabChainMutable", "StabChainOptions" ] gap> Size(g); 60 gap> EnableAttributeValueStoring(Size); #I Enabling value storing for Size gap> Size(g); 60 gap> KnownAttributesOfObject(g); [ "Size", "One", "LargestMovedPoint", "NrMovedPoints", "MovedPoints", "GeneratorsOfMagmaWithInverses", "MultiplicativeNeutralElement", "StabChainMutable", "StabChainOptions" ]
[Top] [Previous] [Up] [Next] [Index]
GAP 4 manual