ephemeron is broken when nobody else cares about its key. Note that
an ephemeron's reference to its datum may be dropped even if the datum
is still reachable; all that matters is whether the key is reachable.
-Once broken, ephemerons never cease to be broken; setting the datum of
-a broken ephemeron with @code{set-ephemeron-datum!} has no effect.
+Once broken, ephemerons never cease to be broken; setting the key or
+datum of a broken ephemeron with @code{set-ephemeron-key!} or
+@code{set-ephemeron-datum!} has no effect.
Ephemerons are considerably heavier-weight than weak pairs, because
garbage-collecting ephemerons is more complicated than
@deffnx procedure ephemeron-datum ephemeron
@cindex selection, of ephemeron component
@cindex component selection, of ephemeron
-These return the key or datum components, respectively, of
-@var{ephemeron}. If @var{ephemeron} has been broken, these operation
+These return the key or datum component, respectively, of
+@var{ephemeron}. If @var{ephemeron} has been broken, these operations
return @code{#f}, but they can also return @code{#f} if that is the
value that was stored in the key or value component.
@end deffn
-@deffn procedure set-ephemeron-datum! ephemeron object
-Sets the datum component of @var{ephemeron} to @var{object} and
-returns an unspecified result. If @var{ephemeron} is broken, this has
-no effect.
+@deffn procedure set-ephemeron-key! ephemeron object
+@deffnx procedure set-ephemeron-datum! ephemeron object
+These set the key or datum component, respectively, of @var{ephemeron}
+to @var{object} and return an unspecified result. If @var{ephemeron}
+is broken, neither of these operations has any effect.
@end deffn
Like @code{weak-pair/car?}, @code{ephemeron-broken?} must be used with
\f
;;;; Ephemerons
+;;; The layout of an ephemeron is as follows:
+;;;
+;;; 0 vector (marked or non-marked) manifest
+;;; 1 key
+;;; 2 datum
+;;; 3 extra
+;;; . slots
+;;; . for
+;;; . GC
+
(define canonical-false (list 'FALSE))
(define (canonicalize object)
(guarantee-ephemeron ephemeron 'EPHEMERON-DATUM)
(decanonicalize (primitive-object-ref ephemeron 2)))
+(define (set-ephemeron-key! ephemeron key)
+ (guarantee-ephemeron ephemeron 'SET-EPHEMERON-KEY!)
+ (let ((key* (primitive-object-ref ephemeron 1)))
+ (if key* (primitive-object-set! ephemeron 1 (canonicalize key)))
+ (reference-barrier key*))
+ unspecific)
+
(define (set-ephemeron-datum! ephemeron datum)
(guarantee-ephemeron ephemeron 'SET-EPHEMERON-DATUM!)
(let ((key (primitive-object-ref ephemeron 1)))
(if key (primitive-object-set! ephemeron 2 (canonicalize datum)))
- ;; Guarantee that the key is referenced until this procedure
- ;; returns.
- (identity-procedure key))
+ (reference-barrier key))
unspecific)
(define (ephemeron-broken? ephemeron)