[plt-scheme] cannot serialize classes with private methods
At Sat, 05 Aug 2006 20:34:05 -0400, Jon Rafkind wrote:
> Im trying to use serialization but cant seem to serialize a class that
> has a method defined not using public. The following code results in
> this error:
>
> serialize: expects argument of type <serializable object>; given
> #<procedure:...kazzmir/tmp/x.ss:7:3>
>
> (require (lib "class.ss")
> (lib "serialize.ss"))
>
> (define-serializable-class foo object%
> (public blah)
> (define (blah) (printf "blah\n"))
> (define (foo) (printf "foo\n"))
> (super-new))
>
> (serialize (new foo))
>
> But if foo is defined as public: (public blah foo) then it works fine. I
> didnt see anything in the manual that said this would work, what am I
> missing?
When you leave out `public', you don't get a private method. Instead,
you get a procedure-valued field.
If you add a `(private foo)' declaration to your class, then `foo' is a
private method, and instances of the class `foo' are serializable.
The difference between a private method and an procedure-valued field
is subtle, and the current syntax of `class' makes the difference too
subtle. The solution isn't obvious, because we want to support macros
in a `class' body that expand to definitions, and it's not clear
whether function definitions from a macro expansion should be treated
automatically as methods.
Matthew