A box is a mutable container that can hold (possibly multiple) values. It can be used as a minimal data storage, or a sort of mutable indirect “pointer”.
Traditionally, a list or a vector has been used for this purpose. However, such datatypes imply sequences of objects, Using boxes emphasizes your intention is just for indirection, and not so much for sequencing.
It is originally introduced by srfi-111, which was later adopted in
scheme.box. Srfi-195 enhances it to deal with
The srfis leave some details to implementations. Here are our choices:
equal?compares their contents when two are not
eqv?. In the spec, when two boxes are
eqv?then they must also be
equal?to each other, but it’s up to the implementation when two are not
When you’re writing portable code, be careful not to depend on the
Returns a fresh box object that contains the value
#t iff obj is a box object.
[SRFI-195] Returns the number of values box holds.
[R7RS box] Returns box’s content. If box has n values, it returns n values.
[SRFI-195] Returns i-th value held in box.
[R7RS box][SRFI-195] Alters the content of box with val …. The numer of values must match the arity of the box. Returns unspecified value.
[SRFI-195] Alters i-th value of box with val. Returns unspecified value.