For Development HEAD DRAFTSearch (procedure/syntax/module):

Next: , Previous: , Up: Core library   [Contents][Index]

6.17 Boxes

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 R7RS-large as scheme.box. Srfi-195 enhances it to deal with multiple values.

The srfis leave some details to implementations. Here are our choices:

When you’re writing portable code, be careful not to depend on the equal? behavior.

Function: box val …

[R7RS box][SRFI-195] Returns a fresh box object that contains the value val ….

Function: box? obj

[R7RS box] Returns #t iff obj is a box object.

Function: box-arity box

[SRFI-195] Returns the number of values box holds.

Function: unbox box

[R7RS box] Returns box’s content. If box has n values, it returns n values.

Function: unbox-value box i

[SRFI-195] Returns i-th value held in box.

Function: set-box! box val …

[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.

Function: set-box-value! box i val

[SRFI-195] Alters i-th value of box with val. Returns unspecified value.


Next: , Previous: , Up: Core library   [Contents][Index]


For Development HEAD DRAFTSearch (procedure/syntax/module):
DRAFT