chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] records in evicted objects


From: Graham Fawcett
Subject: Re: [Chicken-users] records in evicted objects
Date: Wed, 23 May 2007 13:36:41 -0400

On 5/23/07, Dan Muresan <address@hidden> wrote:
Evicted objects do not work with srfi-9 records for some reason:

   (define-record-type :pare
     (kons x y)
     pare?
     (x kar set-kar!)
     (y kdr))

(kar (object-evict (kons 1 2)))
Error: bad argument type - not a structure of the required type

The zeroth "slot" of the record contains the symbol representing its
type. When you evict the record, you also evict the symbol. The
interned and uninterned symbols are not equal, hence the type-check
failure when it is inspected.

(equal? :pare (object-evict :pare)) => #f

You could set the slot-value back to the non-evicted, interned symbol:

(let ((p (object-evict (kons 1 2))))
 (##sys#setslot p 0 :pare)
 (kar p))
=> 1

or a more general way:

(define (reintern-record-symbol! rec)
 (##sys#setslot rec 0
                 (string->symbol (->string
                                  (##sys#slot rec 0)))))

(let ((p (object-evict (kons 1 2))))
 (reintern-record-symbol! p)
 (kar p))

I'm not sure what the implications of this are, though. Maybe your
process will blow up after GC. :-)

Graham




reply via email to

[Prev in Thread] Current Thread [Next in Thread]