From: Timothy J. H. <ti...@cs...> - 2004-03-03 20:03:40
|
I'd like to see the patch, but it wasn't attached to my email... I am interested in getting serialization to work.... and specifying precisely what its semantics is.... ---Tim--- On Wednesday, March 3, 2004, at 02:34 PM, Toby Allsopp wrote: > Attached is a patch that allows one to serialize a closure (or most > other objects) and read it back in a different process. > > Given the following definitions: > > (import "java.io.*") > > (define (serialize filename x) > (let* ((fos (FileOutputStream. filename)) > (oos (ObjectOutputStream. fos))) > (.writeObject oos x) > (.close oos))) > > (define (deserialize filename) > (let* ((fis (FileInputStream. filename)) > (ois (ObjectInputStream. fis)) > (x (.readObject ois))) > (.close ois) > x)) > > one can do the following: > > JScheme 6.2 1/22/2004 http://jscheme.sourceforge.net > > >> (define qux 42) > 42 >> (define (baz) qux) > (lambda baz ()...) >> (define (foo) baz) > (lambda foo ()...) >> (foo) > (lambda baz ()...) >> ((foo)) > 42 >> (serialize "foo.ser" foo) > #null >> > Process scheme finished > > > JScheme 6.2 1/22/2004 http://jscheme.sourceforge.net > > >> (define bar (deserialize "foo.ser")) > (lambda foo ()...) >> (bar) > (lambda baz ()...) >> ((bar)) > 42 >> baz > (lambda baz ()...) >> qux > 42 >> (set! qux 20) > 20 >> ((bar)) > 20 >> > Process scheme finished > > > JScheme 6.2 1/22/2004 http://jscheme.sourceforge.net > > >> (define qux 10) > 10 >> (define bar (deserialize "foo.ser")) > (lambda foo ()...) >> ((bar)) > 10 > > What happens is that any free references in the closure have their > values snapshotted on serialization and these snapshot values are used > to reestablish the top level bindings if none exist on deserialization. > If the appropriate binding do exists then the free references are > hooked > up as I would expect (but you may not). > > Anyway, I thought this was pretty cool. Is there any interest in > including this patch in the official sources? > > Toby. > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Jscheme-user mailing list > Jsc...@li... > https://lists.sourceforge.net/lists/listinfo/jscheme-user |