Next: Common, Up: actor-lib: A standard library of sorts [Contents][Index]
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.
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
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: ...
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 for creating a cell using a form like Scheme define
.
> (define-cell chest 'gold) > ($ chest) => 'gold
Next: Common, Up: actor-lib: A standard library of sorts [Contents][Index]