[comp.lang.smalltalk] Saving recursive lists to files in Smalltalk/V

marcap@concour.CS.Concordia.CA (Marc Pawlowsky) (05/07/89)

I was earlier trying to save to disk the neural net given in goodies
#3.  I have not been able to figure out a way to save an object
that is recursive to a file and read it back again.  For example
your typical circular list

       A -> B -
       ^       |
       \-------/

Has anybody been able to do this.  If so how?  StoreString (Object)
does not work.  
 

px@unl.fctunl.rccn.pt (Joaquim Baptista (pxQuim)) (05/08/89)

In article <820@sunkisd.CS.Concordia.CA> marcap@concour.CS.Concordia.CA (Marc Pawlowsky) writes:

>   From: marcap@concour.CS.Concordia.CA (Marc Pawlowsky)
>   Date: 6 May 89 20:33:10 GMT
>   Sender: usenet@Sunkisd.CS.Concordia.CA
>   Reply-To: marcap@concour.CS.Concordia.CA (Marc Pawlowsky)
>   Organization: Concordia University, Montreal Quebec
>
>   I was earlier trying to save to disk the neural net given in goodies
>   #3.  I have not been able to figure out a way to save an object
>   that is recursive to a file and read it back again.  For example
>   your typical circular list
>
>	  A -> B -
>	  ^       |
>	  \-------/
>
>   Has anybody been able to do this.  If so how?  StoreString (Object)
>   does not work.  



	You don't say what version of Smalltalk you are using, and so
I will assume you use some "standard" Smalltalk-80.
	In Smalltalk/V for the IBM PC, however, there is a "goodies"
package with a routine which does what you want to, namely, saves any
set of objects (instances, not classes). It has some restrictions,
namely that the structure of the classes of the objects must not
change between "save" and "load" operations.

	The "save format", however, does not ressemble the "readable"
style of "storeString". Since I'me writting the following lines from
memory, you should take them as an apoach to the real thing rather
than the thing itself.
	Each object to be saved is coded as an integer, and the
relation "object - integer" is built into an IdentityDictionary. This
dictionary is used to ensure both that a "shared" object is not saved
twice and that it is allways refered thru the same integer code.
	An Object is then saved in a text file as a series of lines:
		- the first is the integer code for the object;
		- next, the class of the object;
		- next, the length of the object;
		- finaly, the definition of the objects in the
		  instance variables of this one. If the object was
		  seen (and thus saved) before, only its integer code
		  is written.
	Special objects, like integers, characters, are represented
thru special codes, starting with a special character ("#", If my
memory is good). Strings and Symbols also have a special treatment.
	Note that this process needs a lot of space in order to build
the "object - integer" relation.

	The "load" phase builds another relation "integer - object",
and uses it to preserve the "sharing" among objects. The objects
themselves are built using the low-level primitives "basicNew",
"basicNew:" and "instanceVarAt:put:".
	Since that no information about the classes used is saved,
their structure must not change. Note also the space needed by the
"integer - object" relation.

	I hope this helps you. Feel free to post or email if you need.

--------
Joaquim Manuel Soares Baptista       BITNET/Internet: px@host.fctunl.rccn.pt
UUCP: ...{mcvax,inria}!inesc!unl!px           PSI/VMS: PSI%(+2680)05010310::PX
ARPA: px%host.fctunl.rccn.pt@mitvma.mit.edu   Phone: (+351) (1) 295-4464 x.0560
                                                Fax: (+351) (1) 295-4461
Snail:  Dept. de Informatica, Universidade Nova de Lisboa
        2825 Monte Caparica, PORTUGAL
--
--------
Joaquim Manuel Soares Baptista       BITNET/Internet: px@host.fctunl.rccn.pt
UUCP: ...{mcvax,inria}!inesc!unl!px           PSI/VMS: PSI%(+2680)05010310::PX
ARPA: px%host.fctunl.rccn.pt@mitvma.mit.edu   Phone: (+351) (1) 295-4464 x.0560
					        Fax: (+351) (1) 295-4461
Snail:	Dept. de Informatica, Universidade Nova de Lis