[plt-scheme] 299.30

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Feb 3 14:19:28 EST 2005

The exp-tagged code in CVS for MzScheme and MrEd is now version 299.30.

The main addition is a new "serialize.ss" module in MzLib.


The `define-serializable-struct' form works at the top level or at the
top level of a module:

  > (print-struct #t)
  > (define-serializable-struct point (x y) (make-inspector))
           ;; (make-inspector) isn't needed for serialization; it's
           ;; just for this demo
  > (define ps (serialize (make-point 1 2)))
  > ps
  (1 ((#f . deserialize-info:point-v0)) 0 () () (0 1 2))
  > (deserialize ps)
  #3(struct:point 1 2)
 
Serialization handles graph structure:

  > (define psx (make-point 1 100))
  > (set-point-x! psx psx)
  > psx
  #0=#3(struct:point #0# 100)
  > (deserialize (serialize psx))
  #0=#3(struct:point #0# 100)

It also supports versioning, in case you to change the structure in the
future:

  > (define-serializable-struct/versions point 1 (x y z)
            ;; Converter for old version:
            ([0 (lambda (x y) (make-point x y z)) #f])
            (make-inspector))
  > (deserialize ps)
  #4(struct:point 1 2 0)
  > (deserialize (serialize (make-point 1 2 3)))
  #4(struct:point 1 2 3)

Of course, if you define serializable struct types at the top level,
you have to load the definitions before you can deserialize. If you put
the definition in a module, though, the deserialization process finds
and loads the module via `dynamic-require'.

 ;; In "s.ss":
  (module s mzscheme
    (require (lib "serialize.ss"))
    (define-serializable-struct point (x y))
    (provide make-a))

 rains.flux.utah.edu% mzscheme -l serialize.ss
 Welcome to MzScheme version 299.30, Copyright (c) 2004-2005 PLT Scheme, Inc.
 > (require "s.ss")
 > (serialize (make-point 1 2))
 (1 (((file "/Users/matthewf/tmp/s.ss") . deserialize-info:point-v0)) 
    0 () () (0 1 2))

 rains.flux.utah.edu% mzscheme -l serialize.ss
 Welcome to MzScheme version 299.30, Copyright (c) 2004-2005 PLT Scheme, Inc.
 > (deserialize '(1 (((file "/Users/matthewf/tmp/s.ss")
                      . deserialize-info:point-v0)) 0 () () (0 1 2)))
 #<struct:point>

If you decide to rename the structure, you can export the old
deserializer with the old name:

 ;; In s.ss:
  (module s mzscheme
    (require (lib "serialize.ss"))
    ;; Renamed to my-point:
    (define-serializable-struct my-point (x y))
    ;; support deserializing points:
    (provide (rename deserialize-info:my-point-v0 deserialize-info:point-v0))
    (provide make-my-point))

  rains.flux.utah.edu% mzscheme -l serialize.ss
  Welcome to MzScheme version 299.30, Copyright (c) 2004-2005 PLT Scheme, Inc.
  > (deserialize '(1 (((file "/Users/matthewf/tmp/s.ss")
                       . deserialize-info:point-v0)) 0 () () (0 1 2)))
  #<struct:my-point>

In general, a serializable struct has the `prop:serializable' property,
so you're not constrained to using `define-serializable-struct' to make
serializable values. See the docs for more details (including details
in the serialization format).

Don't commit large amounts of data to the current serialization format,
yet! But do try it out and let us know how well it works.


Other changes:

 * Structure type properties are now overridable in subtypes.

 * Added `module-compiled-exports'.

 * Added `continuation-mark-set->list*'.

 * Immediate instances of object% are now transparent, just like a
   struct created with `(make-inspector)', and new classes craete
   transparent instances when the class creation is parameterized by an
   inspector. Example:

    > (define c%
        (parameterize ([current-inspector (make-inspector)])
          (class object%
            (init-field x y)
            (super-new))))
    > (print-struct #t)
    > (new c% [x 10] [y 12])
    #3(struct:object:c% 10 12)
    > (equal? (new c% [x 10] [y 12]) (new c% [x 10] [y 12]))
   #t


Matthew



Posted on the users mailing list.