Next: , Previous: Symbols, Up: Miscellaneous Datatypes


10.3 Cells

Cells are data structures similar to pairs except that they have only one element. They are useful for managing state.

— procedure: cell? object

Returns #t if object is a cell; otherwise returns #f.

— procedure: make-cell object

Returns a newly allocated cell whose contents is object.

— procedure: cell-contents cell

Returns the current contents of cell.

— procedure: set-cell-contents! cell object

Alters the contents of cell to be object. Returns an unspecified value.

— procedure: bind-cell-contents! cell object thunk

Alters the contents of cell to be object, calls thunk with no arguments, then restores the original contents of cell and returns the value returned by thunk. This is completely equivalent to dynamic binding of a variable, including the behavior when continuations are used (see Dynamic Binding).