[GAP Forum] Why do my objects do not store attributes?

Rafael Villarroel rafaelv at uaeh.edu.mx
Fri May 27 22:11:03 BST 2016


Hello GAP forum

I'm puzzled as to why the following code, which I think should work,
does not. I have reduced the situation to the following:

--------------- start tempo.gap

DeclareCategory("IsMyStruct", IsObject);
StrFamily := NewFamily("MyStructsFamily");
StrType := NewType(StrFamily, IsMyStruct);
DeclareRepresentation("StrRep",
                      IsComponentObjectRep and IsAttributeStoringRep,
                      ["uno", "dos"]);
CreateStr := function(u,v)
    return Objectify(StrType,rec(uno:=u,dos:=v));
end;

InstallMethod(PrintObj,[IsMyStruct],function(S) Print("uno=",S!.uno,"dos=",S!.dos);
                                    end);
InstallMethod(ViewObj,[IsMyStruct],function(S) Print("uno=",S!.uno,"dos=",S!.dos);
              end);

DeclareAttribute("MyAtr",IsMyStruct);
InstallMethod(MyAtr,[IsMyStruct],function(S) return("hello");
                                 end);

DeclareProperty("MyProp",IsMyStruct);
InstallMethod(MyProp,[IsMyStruct],function(S) return false;
                                 end);

--------------- end tempo.gap

then, after loading in a GAP 4.8.2 session, started with "gap -r":
I get:

gap> Read("tempo.gap");
gap> S:=CreateStr(1,2);
uno=1dos=2
gap> MyAtr(S);
"hello"
gap> KnownAttributesOfObject(S);
[  ]

why is that? However, storing of properties work?

gap> MyProp(S);
false
gap> KnownPropertiesOfObject(S);
[ "MyProp" ]

Thanks in advance for any help.

Rafael











More information about the Forum mailing list