Next: Swappable, Previous: Selfish-Spawn, Up: actor-lib: A standard library of sorts [Contents][Index]
The (goblins actor-lib simple-mint)
module provides an example
actor simulating a mint and currency. This is a Goblins
implementation of a
classic example
of object capabilities.
Constructor an actor which in turn constructs and returns
purse
s for its currency. A mint
only has one method:
new-purse initial-balance
spawns and returns a reference to a
new purse
which holds initial-balance tokens.
A purse
, on the other hand, has four methods:
get-balance
: Return the current number of tokens in the purse.
sprout
: Spawn and return a reference to a new empty
purse
for this currency.
deposit amount src
: Increase the number of tokens in this
purse
by amount, decreasing the number of tokens in the
purse
of the same currency src by the same amount.
get-decr
: Return a procedure accepting one argument, an
amount of tokens to remove from this purse
.
Spawn and return a reference to a new purse holding amount
tokens of the same type as the purse
from-purse. Remove
the same numbers of tokens from from-purse.