[plt-scheme] 299.105

From: Erich Rast (erich at snafu.de)
Date: Sun May 8 14:41:51 EDT 2005

>  * Added `define-serializable-class[*]' to MzLib's "class.ss".


I have troubles with a subclass of a class that is just a wrapper for 
hash-tables. I guess it's something simple, but I can't see why the 
code below gives an error. Serializing hash-table% works, but 
serializing its subclass fails even though both are serializable.  
(Sorry, I haven't found a simpler example yet. Language is Pretty Big.)

;;;;;;;;;;;;;;;; BEGIN SAMPLE
(require (lib "class.ss")(lib "serialize.ss"))

;; generic hash-table class (object wrapper)
   hash-table% object% ()
   (public put get remove count (table-for-each for-each) (table-map 
   (field (table (make-hash-table 'equal)))

   (define (put key v)
     (hash-table-put! table key v))

   (define get
       [(key failure-thunk) (hash-table-get table key failure-thunk)]
       [(key) (hash-table-get table key (lambda () #f))]

   (define (remove key)
     (hash-table-remove! table key))

   (define (count)
     (hash-table-count table))

   (define (table-for-each proc)
     (hash-table-for-each table proc))

   (define (table-map proc)
     (hash-table-map table proc))


;; generic ordered collection class
;; stores keys and values and allows access to keys and value
   collection% hash-table% ()
   (inherit for-each map)
   (public add-item remove-item get-item count-items)
   (define keys null)

   (define (add-key key)
     (set! keys (append keys (list key))))

   (define (remove-key key)
     (set! keys (remove key keys)))

   (define (add-item key v)
     (send this put key v)
     (add-key key))

   (define (remove-item key)
     (send this remove key) (remove-key key))

   (define (get-item key)
     (cond ((number? key) (send this get (list-ref keys key)))
           (else (send this get key))))

   (define (count-items)
     (send this count))


(define test (new collection%))
(serialize test)
;;;;;;;;;;;;;;;;;;; END SAMPLE

==> serialize: expects argument of type <serializable object>; given 

Posted on the users mailing list.