Next: , Up: actor-lib: A standard library of sorts   [Contents][Index]


6.1 Cell

The (goblins actor-lib cell) module provides a very handy actor called a “cell.” Cells are used to store arbitrary data. It also provides some helper functions for cells.

Constructor: ^cell bcom [val #f]

Construct an actor which contains val or #f if val is not provided.

> (define empty-chest (spawn ^cell))
> (define chest (spawn ^cell 'gold))

Cells have two possible invocations: with no arguments, which returns the current value; and with one argument, which sets a new value and returns nothing.

> ($ chest)
=> 'gold
> ($ chest 'sword)
> ($ chest)
=> 'sword
Procedure: cell->read-only cell

Create and return a read-only proxy to cell. It is an error to attempt to write to such a cell.

> (define ro-chest (cell->read-only chest))
> ($ chest)
=> 'sword
> ($ chest 'wand)
=> error: ...
Procedure: cell->write-only cell

Create and return a write-only proxy to cell. It is an error to attempt to read from such a cell.

> (define wo-chest (cell->write-only chest))
> ($ chest 'wand)
> ($ chest)
=> error: ...
Syntax: define-cell id [val #f]

Syntax for creating a cell using a form like Scheme define.

> (define-cell chest 'gold)
> ($ chest)
=> 'gold
Persistence Environment: cell-env

Next: Common, Up: actor-lib: A standard library of sorts   [Contents][Index]