I suggest providing another procedure REFERENCE-BARRIER that
guarantees whatever object you pass to it will not have been GC'd
before the call to REFERENCE-BARRIER. For example, you can use it to
address Takeshi Abe's question about the usage idiom:
(let ((key (ephemeron-key e)))
(if (not (ephemeron-broken? e))
(let ((datum (ephemeron-datum e)))
(reference-barrier key)
...)))
The example implementation in Racket is incorrect.
(define (ephemeron-broken? ephemeron)
(not (ephemeron-value ephemeron)))
(define (ephemeron-key ephemeron)
(car (ephemeron-value ephemeron)))
(define (ephemeron-datum ephemeron)
(cdr (ephemeron-value ephemeron)))
The correct idiom for using an ephemeron,
(let ((key (ephemeron-key e)))
(if (not (ephemeron-broken? e))
...use key...)),
may cause an attempt to take the car of #f, in this implementation.
Some of the text was lifted verbatim from the MIT Scheme reference
manual, including most of the paragraph starting `This procedure must
be used with care...'. This should be acknowledged. (It's also not
clear which procedure `this procedure' refers to.)
I encourage providing some automatic tests. Here's a place you might
start:
http://git.savannah.gnu.org/cgit/mit-scheme.git/plain/tests/runtime/test-ephemeron.scm
Racket likely has some automatic tests too.
I also encourage providing some direction for implementations: it is
not immediately clear how to make a GC efficiently handle ephemerons.
Here are two examples:
http://mumble.net/~campbell/tmp/ephemeron.scm
http://mumble.net/~campbell/tmp/ephemeron-hash.scm
I would be happy to provide them under an appropriate licence for
inclusion in the SRFI if you like.
You should also cite Bruno Haible's paper:
Bruno Haible, `Weak References: Data Types and Implementation', 2005-04-24.
http://www.haible.de/bruno/papers/cs/weak/WeakDatastructures-writeup.html
Ephemerons are what he calls `weak key mappings'.