Weak Pairs (MIT/GNU Scheme 12.1)

Next: Ephemerons, Previous: Weak References, Up: Weak References [Contents][Index]

#### 10.7.1 Weak Pairs

The car of a weak pair holds its pointer weakly, while the cdr holds its pointer strongly. If the object in the car of a weak pair is not held strongly by any other data structure, it will be garbage-collected, and the original value replaced with a unique reclaimed object.

Note: weak pairs can be defeated by cross references among their slots. Consider a weak pair P holding an object A in its car and an object D in its cdr. P points to A weakly and to D strongly. If D holds A strongly, however, then P ends up holding A strongly after all. If avoiding this is worth a heavier-weight structure, See Ephemerons.

Note: weak pairs are not pairs; that is, they do not satisfy the predicate `pair?`.

procedure: weak-pair? object ¶

  Returns `#t` if object is a weak pair; otherwise returns `#f`.

procedure: weak-cons car cdr ¶

  Allocates and returns a new weak pair, with components car and cdr. The car component is held weakly.

procedure: gc-reclaimed-object? object ¶

  Returns `#t` if object is the reclaimed object, and `#f` otherwise.

procedure: gc-reclaimed-object ¶

  Returns the reclaimed object.

obsolete procedure: weak-pair/car? weak-pair ¶

  This predicate returns `#f` if the car of weak-pair has been garbage-collected; otherwise returns `#t`. In other words, it is true if weak-pair has a valid car component.

  This is equivalent to

      (not (gc-reclaimed-object? (weak-car weak-pair)))

  This predicate has been deprecated; instead use `gc-reclaimed-object?`. Please note that the previously recommended way to use `weak-pair/car?` will no longer work, so any code using it should be rewritten.

procedure: weak-car weak-pair ¶

  Returns the car component of weak-pair. If the car component has been garbage-collected, this operation returns the reclaimed object.

procedure: weak-set-car! weak-pair object ¶

  Sets the car component of weak-pair to object and returns an unspecified result.

procedure: weak-cdr weak-pair ¶

  Returns the cdr component of weak-pair.

procedure: weak-set-cdr! weak-pair object ¶

  Sets the cdr component of weak-pair to object and returns an unspecified result.

Next: Ephemerons, Previous: Weak References, Up: Weak References [Contents][Index]