scsh-0.6/scsh/weaktables.scm

31 lines
956 B
Scheme
Raw Permalink Normal View History

;;; Tail-weak tables. This is for internal use only, for real life
;;; applications we have to provide a more general interface with the
;;; 3 combinations of head and tail weakness.
(define make-weak-table make-table)
(define (weak-table-set! table number set-me)
2002-02-13 09:36:10 -05:00
(table-set! table number (if set-me (make-weak-pointer set-me) #f)))
(define (weak-table-ref table number)
(let ((ref (table-ref table number)))
(if (weak-pointer? ref)
(let ((val (weak-pointer-ref ref)))
(if val
val
(begin (table-set! table number #f)
#f)))
ref)))
(define (weak-table-walk proc table)
(table-walk
(lambda (number value)
2001-10-03 10:40:04 -04:00
(proc number (if (weak-pointer? value) (weak-pointer-ref value) value)))
table))
(define (strengthen-weak-table-ref table number)
(table-set! table number (weak-table-ref table number)))
(define (weaken-weak-table-ref table number)
(weak-table-set! table number (weak-table-ref table number)))