Next: Facet, Previous: Cell, Up: actor-lib: A standard library of sorts [Contents][Index]
The (goblins actor-lib common)
module provides actors wrapping
functional data structures, allowing Goblins transactionality
guarantees while providing an apparently mutable interface.
Construct an actor representing a set (each member is unique). A
seteq
has four methods:
add val
: Add val to the set.
remove val
: Remove val from the set.
member? val
: Return #t
if val is in the set, else
#f
.
as-list
: Return a representation of the set as a Scheme list.
Note that the order of items in the list is not specified.
> (define a-set (spawn ^seteq 'a 'b 'c)) > ($ a-set 'as-list) => (a b c) > ($ a-set 'member? 'c) => #t > ($ a-set 'member? 'f) => #f > ($ a-set 'add 'f) > ($ a-set 'remove 'b) > ($ a-set 'as-list) => (f c a)
Construct an actor representing a hashtable using eq?
for
key lookup and equal?
for other comparisons. ht, if
provided, is the underlying ghash
to use as the starting state.
See (goblins ghash)
module for the compatible hashtable
implementation.
A ghash
actor has five methods:
ref key [dflt #f]
: Return the value associated with key,
or dflt if the key is not found.
set key val
: Add key to the ghash
and associate it
with val.
has-key? key
: Return #t
if key is in the
ghash
; otherwise return #f
.
remove key
: Delete key and its associated value from the
ghash
.
data
: Return the underlying ghash
.
> (define ag (spawn ^ghash)) > ($ ag 'set "dog" "animal") > ($ ag 'set "cesna" "plane") > ($ ag 'data) => $<ghash (2)> > ($ ag 'ref "cesna") => "plane" > ($ ag 'has-key? "dog") => #t > ($ ag 'remove "cesna") > ($ ag 'ref "cesna") => #f > ($ ag 'ref "cesna" 'missing) => missing > ($ ag 'data) => $<ghash (1)>
Next: Facet, Previous: Cell, Up: actor-lib: A standard library of sorts [Contents][Index]