GAP Project repository
  

Save Object

Need:
5
Time:
3
Component: Library
Contact: Alexander Hulpke
( hulpke@math.colostate.edu)
Last Update: 2004/6/29
Math:
2
Program:
3


Description

Implement functionality to save single objects to a file and to load them in later.

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 equivalent objects to the ones saved (I'm not using equal\ because reading in again a saved file will for example for finitely presented groups create *new* objects that are not *equal* to the old ones. It also will not save all known attributes and properties. If this is desired the save workspace facility must be used).

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 save context (an object used for tracking information about things already saved). If we agree that at most one save context may be open at any time, this may as well be a hidden global variable.

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.)

Some more detail:

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 small known attributes (for example a permutation groups size) but for debugging purposes it must be possible to switch this feature off.

There are several problems and caveats:


GAP home page