From: Toby A. <tob...@pe...> - 2004-03-03 19:48:57
|
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. |
From: Toby A. <tob...@pe...> - 2004-03-03 19:57:25
Attachments:
serialization.diff
|
And here is the patch. (I *always* forget to attach the bloody things). Toby. |
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 |
From: Ken A. <kan...@bb...> - 2004-03-03 20:37:00
|
This looks like a very nice job! You even fixed serialization of Pairs and Symbols! I've really wanted to fix serialization for a long time. Thanks for doing it! Tim, maybe this would let us have separate heaps, like SISC does. At 02:49 PM 3/3/2004 -0500, Timothy John Hickey wrote: >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 > > > >------------------------------------------------------- >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 |
From: Toby A. <tob...@pe...> - 2004-03-03 20:53:46
|
On Wed, Mar 03, 2004 at 02:49:59PM -0500, Timothy John Hickey wrote: > 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.... Yeah, sorry about that, I've sent it in a separate reply. The semantics are tricky to specify. What I've implemented is the behaviour I happen to want, but it has the slightly strange side effect of introducing new top level bindings to satisfy free references on deserialization. I see two alternatives: 1) assume that the bindings exist and generate an error if they don't, just as if the closure was defined normally, 2) just use the snapshotted values and avoid polluting the top level. I think what I've implemented is more useful in general, and it certainly is for me. Toby. > > 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. |
From: Ken A. <kan...@bb...> - 2004-03-05 22:38:20
|
I've checked in Toby's code with some minor modifications. also elf/serialize.scm has some example code. I'll probably make a couple of small changes next week. |
From: Ken A. <kan...@bb...> - 2004-03-09 20:29:55
|
I'll let Tim answer this one. k At 08:14 PM 3/8/2004 -0800, david wrote: >I need to use JTables so I made these modifications to >JLIB.scm.. Seems to work okay. JTable manages it's >data with a TableModel so all the data manipulation >is handeled there. I used the name matrix for the >table widget since table is arleady used.. > >Maybe we can get somthing like this is the standard >jar file? > > > > >(define matrix (lambda R > (define M (javax.swing.JTable. (first R))) > (processConArgs M R) > M)) > >and adding > >((javax.swing.JTable javax.swing.JTable javax.swing.table.TableModel) > (.add a c)) > >to processConArgs > > > >;;;;;;;;;;; >(define t (maketagger)) >(define tm (javax.swing.table.DefaultTableModel. 20 2)) > >(define w > (window "Test" > (t "mat1" (matrix tm)) > (button "exit" red > (action(lambda(e)(exit)))))) >(.pack w) >(.show w) >(.getDataVector tm) >(.setValueAt tm "helo" 0 0 ) >;;;;;;;;;; |