Next: , Up: iklib lists   [Index]


6.25.1 Weak pairs

Weak references do not cause the referenced value to be considered used by the garbage collector. The following bindings are exported by the library (vicare).

Function: weak-cons A D

Like cons build and return a new pair, but holding weak references to A; notice that the reference to D is not weak. This function allows to build a non–weak list spine holding weak references to values.

Function: weak-pair? obj

Return true if obj is a weak pair.

Function: bwp-object

Return the BWP object. BWP stands for “broken weak pointer”.

Function: bwp-object? obj

Return true if obj is a weak reference to a value which has been already garbage collected. Example:

vicare> (define x (weak-cons (cons 1 2) #f))
vicare> x
((1 . 2) . #f)
vicare> (bwp-object? (car x))
#f
vicare> (collect)
vicare> x
 (#!bwp . #f)
vicare> (bwp-object? (car x))
#t