[plt-scheme] serializing /all/ of struct

From: Daniel Yoo (dyoo at cs.wpi.edu)
Date: Tue Feb 13 10:25:19 EST 2007

> In MzScheme, why doesn't serialize work, and fully, by default??  Ie, 
> (serialize my-object) should write out everything scheme needs to 
> deserialize the object, without the special define, require'd file, and 
> inspector

Hi George,

The documentation to serialize explains that it's designed so that you can 
version the structures:

http://download.plt-scheme.org/doc/360/html/mzlib/mzlib-Z-H-39.html#node_chap_39

So at least from that reason, the structure definition needs to live 
somewhere outside of the actual data, because that definition must be 
checked later for its version data vs the data's version.


But it's also a little unclear what it means to restore a struct type 
on-the-fly: if I have some arbitrary file with a structure in it, I might 
be able to restore it, but then, how do I access and use it?  How would my 
program know what the accessor names would be?

I think you're expecting structure deserialization to automatically 
introduce identifiers for our accessors and mutators.  But that can be a 
problem: we'd like to avoid magically introducing new identifiers at 
run-time because it breaks things like lexical scoping.

I'm pretty sure you can do something to approximate what you want, with 
some judicious use of EVAL to introduce the structure definitions at 
run-time, but I'm not sure it's worth it since it would break all the 
static analysis tools like Check-Syntax.  Is there something big that 
stops you from storing the structure definitions in a module?


I guess I'm trying to say: what you're asking for sounds a bit unusual, 
and more than what most people need out of serialize.ss.  If you really 
need that kind of dynamic structure regeneration, you'll probably need to 
do something special that involves more than just a direct use of 
serialize.ss.


Best of wishes!


Posted on the users mailing list.