Save Object |
Need: |
Time: |
|
Component:
Library Contact: Alexander Hulpke ( hulpke@math.colostate.edu) Last Update: 2004/6/29 |
Math: |
Program: |
On a basic level this is provided by the Print command. However this does not save associated attributes.
The task thus essentially is to
The following text is an outline from 1998 for such a scheme.
It will yield a
GAP
file that when reading in
creates
When saving an object enough context must be saved to create the object. That is for a finitely presented group the corresponding free group and the relators have to be saved as well. When storing a subgroup the parent has to be printed before. We have to be careful, however, when saving say several subgroups of an fp group. In this situation the parent must be printed only once and all parent references must be to this object. Also it may be necessary or desirable to assign the parent generators to temporary variables to permit reasonable printing of words that generate the subgroups.
To keep track of relations among the objects and about whether objects have been saved already, saving is a multiple stage process:
ctx:=StartSave(<filename>);initiates saving of objects on the indicated file it returns a
The operation
Save(<ctx>,<obj>,<varname>)saves the object <obj> in the context <ctx>, using variable name &\ lt;varname> (we cannot obtain a variable name from an object).
EndSave(<ctx>) closes a save context. (Depending on the objects involved\ , it may be necessary to delay the actual writing to the file to this point. Before ending a save context it can not be guaranteed that the file is usable.)
The save context stores all objects saved with the (temporary) variable name under which they were saved. Therefore Save first checks if the objec\ t is already saved in the given context and if yes just adds a corresponding variable assignment. Otherwise Save will call an operation SaveObj (same syntax) \ for which suitable methods for all object must be installed. SaveObj will first Save (i.e. save only if not yet done) all objects needed for the creation under temporary variables (the save context will keep track of the temporary variables used) and then print a command that will create the object under the indicated variable name, using the objects it depends on saved before. (It seems a function VariableSavedObject(<ctx>,<obj>) tha\ t saves the object <obj> if not yet done and returns the variable name under which i\ t was saved should be used here.
For example if U is a subgroup of an fp group,
Save(<ctx>,U,"U")first calls
parnam:=VariableSavedObject(<ctx>,Parent(U)) (which recursively saves \ free group, presentation &c.) and gen:=VariableSavedObject(GeneratorsOfGroup(Parent(U)));and then prints via
AppendTo(ctx.file,varnam":=Subgroup(",parnam,","[" ...&c.
The save routine may want to store some There are several problems and caveats:
A:=[]; B:=[A]; # added later: A[1]:=B;The easiest way to cope with this seems to be to store in the context which objects are currently being saved and to stop recursions when again saving these objects, instead noting in the context the assignment necessary at the end to close the loop again and printing it only after the object itself had been printed.