For Gauche 0.9.10

Next: , Previous: , Up: 組み込みライブラリ   [Contents][Index]

6.17 ボックス

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 Srfi-195 enhances it to deal with multiple values.

The srfis leaves 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: 組み込みライブラリ   [Contents][Index]