[GAP Forum] Persistant storage of attributes

Bob Heffernan bob.heffernan at gmail.com
Mon Jun 29 13:55:39 BST 2020


Dear all,

Using DeclareAttribute and then the appropriate getters and setters for
that attribute seems to be a good way to "memoize" a computation in GAP.

I often find myself trawling through the small-groups library.  If I do
something like

DeclareAttribute( "Foo", IsGroup );
G:=SmallGroup(8,3);
# pretend that some involved computation computes the value bar
SetFoo(G,bar);

then, for the rest of the session I can use HasFoo(G) and Foo(G) to
avoid repeating my computation.  However, the attribute Foo is
associated to the object referenced by the identifier G.  If I overwrite
G, say I do
G:=SmallGroup(8,3);
again, then my stored attribute is lost.  This makes sense.

The result of
IsAttributeStoringRep(SmallGroup(8,3));
is "true" but attempting to set my custom attribute for SmallGroup(8,3)
directly seems to do nothing: it is not listed when I run
KnownAttributesOfObject(SmallGroup(8,3)).

What I would really like to do is set attributes for groups in the small
groups library in such a way that this information persists between
sessions.  Is there any way to do this or any way to achieve something
similar?  I guess I could have a big hash-table storing the information
I want, perhaps with small-group IDs as the keys, which I could read at
the beginning of a session and write at the end, but I'm wondering if
there is a more idiomatic way to do things.

Thanks & best regards,
Bob



More information about the Forum mailing list