Next: , Previous: Hash tables, Up: System features


4.1.10 Weak references

Scheme48 provides an interface to weakly held references in basic weak pointers and populations, or sets whose elements are weakly held. The facility is in the structure weak.

4.1.10.1 Weak pointers
— procedure: make-weak-pointer contents –> weak-pointer
— procedure: weak-pointer? object –> boolean
— procedure: weak-pointer-ref weak-pointer –> value or #f

Make-weak-pointer creates a weak pointer that points to contents. Weak-pointer? is the weak pointer disjoint type predicate. Weak-pointer-ref accesses the value contained within weak-pointer, or returns #f if there were no strong references to the contents and a garbage collection occurred. Weak pointers resemble cells, except that they are immutable and hold their contents weakly, not strongly.

4.1.10.2 Populations (weak sets)
— procedure: make-population –> population
— procedure: add-to-population! object population –> unspecified
— procedure: population->list population –> list
— procedure: walk-population proc population –> unspecified

Make-population constructs an empty population. Add-to-population! adds object to the population population. Population->list returns a list of the elements of population. Note, though, that this can be dangerous in that it can create strong references to the population's contents and potentially leak space because of this. Walk-population applies proc to every element in population.