Status: useful, does the concept as well as the mechanism
Description: guardians are another in the long line of powerful abstractions that scheme embraces. Their essential purpose it to provide a powerful finalization mechanism for dead objects. How this works is that you create a guardian G. For every object that you want to be protected, you do a (G obj). Now, after a garbage collection, you can retrieve each of the objects that were not traced (and therefore dead) by doing (G). An example:
(define G (make-guardian)) (G (cons 'a 'b)) ;;; Notice the only reference to that cons is in G (gc) (G) => (a . b) (G) => #f
This provides us with a very flexible and garbage collector independant way of doing object finalization.
Note: the definitive reference for guardians is at ftp://ftp.cs.indiana.edu/pub/scheme-repository/doc/pubs/guardians.ps.gz The implementation is much the same as with the guile version.
Note: there's no particular special treatment given to a guardian object itself. It won't hang around if there's no reference to it, and it'll take all of your objects with it.
Note: the underlying structures holding the objects are called tconc's, which is a bizarre lisp way of saying "queue implemented with a cons cell, where the car points to a list, and the cdr points to the tail of the list".
Note: the guardian itself is actually just a cclo, which
contains a slot for the guardian itself, and dispatches on either
scm_guard or scm_get_one_zombie. (an interesting thing I
noticed is that a cclo appears to use the values of it's slots for
optional arguments, but don't quote me on that, 'cause I'm not quite
sure if that's entirely accurate).
scm_igc.
scm_guard
if arg is given, or scm_get_one_zombie if arg is
undefined.