Skip to content

Commit ecfb86a

Browse files
authored
Document setter for mutable attributes (#6198)
In particular, add an example that shows the differences. (I do not like it at all that setters of mutable attributes replace stored values, but I think it is too late to change this behaviour.)
1 parent e019806 commit ecfb86a

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

doc/ref/types.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,34 @@ for example, <C>Setter( Size )( <A>obj</A>, <A>val</A> )</C>
533533
sets <A>val</A> as size of the
534534
object <A>obj</A> if the size was not yet known.
535535
<P/>
536+
Calling the setter an of attribute for an object which stores already
537+
a value for this attribute <E>has no effect</E>,
538+
except if the attribute has been created as a <E>mutable</E> attribute
539+
(see <Ref Func="NewAttribute"/>).
540+
For mutable attributes, each call of the setter
541+
<E>replaces the stored value</E>.
542+
(Usually mutable attributes are used to store a mutable list or record once,
543+
and later add data to this value, and then one should take care not to call
544+
the setter of the attribute again.)
545+
<P/>
546+
<Example><![CDATA[
547+
gap> imm_attr:= NewAttribute( "imm_attr", IsGroup );;
548+
gap> mut_attr:= NewAttribute( "mut_attr", IsGroup, "mutable" );;
549+
gap> G:= SymmetricGroup( 4 );;
550+
gap> Setter( imm_attr )( G, 0 );
551+
gap> imm_attr( G );
552+
0
553+
gap> Setter( imm_attr )( G, 1 ); # This call has no effect.
554+
gap> imm_attr( G );
555+
0
556+
gap> Setter( mut_attr )( G, 0 );
557+
gap> mut_attr( G );
558+
0
559+
gap> Setter( mut_attr )( G, 1 ); # This call replaces the stored value.
560+
gap> mut_attr( G );
561+
1
562+
]]></Example>
563+
<P/>
536564
For each attribute <A>attr</A> that is declared with
537565
<Ref Func="DeclareAttribute"/> resp.&nbsp;<Ref Func="DeclareProperty"/>,
538566
tester and setter are automatically made accessible by the names

lib/oper.g

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,9 +1272,10 @@ end );
12721272
## <Ref Oper="SylowSubgroup"/>,
12731273
## and this list is mutable because one may want to enter groups into it
12741274
## as they are computed.
1275-
## <!-- in the current implementation, one can overwrite values of mutable-->
1276-
## <!-- attributes; is this really intended?-->
1277-
## <!-- if yes then it should be documented!-->
1275+
## <P/>
1276+
## Mutable and immutable attributes behave differently w. r. t. repeated
1277+
## calls of the function that sets the attribute value,
1278+
## see <Ref Func="Setter"/>.
12781279
## <P/>
12791280
## If no argument for <A>rank</A> is given, then the rank of the tester is 1.
12801281
## <P/>

0 commit comments

Comments
 (0)