weak tables with weak value

This commit is contained in:
eknauel 2004-02-13 16:53:40 +00:00
parent da9ad48831
commit 7203d9d9f8
1 changed files with 24 additions and 0 deletions

24
scheme/weak-table.scm Normal file
View File

@ -0,0 +1,24 @@
;;; weak table with weak values
(define-record-type weak-table
(really-make-weak-table table)
weak-table?
(table weak-table-table))
(define (make-value-weak-table)
(really-make-weak-table (make-integer-table)))
(define (add-to-weak-table! table address object)
(table-set! (weak-table-table table)
address
(make-weak-pointer object)))
(define (remove-from-weak-table! table address)
(table-set! (weak-table-table table)
address #f))
(define (lookup-in-weak-table table address)
(cond
((table-ref (weak-table-table table) address)
=> weak-pointer-ref)
(else #f)))