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


6.7 Nonce Registry

The (goblins actor-lib nonce-registry) module provides an actor to store and retrieve references using swiss-nums. A swiss-num is a string of digits which grants anyone with that string of digits access to whatever it refers to, much as a Swiss bank account number grants access to the bank account (hence the name).

Procedure: spawn-nonce-registry-and-locator

Create and return, as values, an actor which registers and an actor which locates objects using Swiss nums.

The first returned value, the registry, has two methods: register, which accepts an object reference and an optional swiss-num, and returns the swiss-num; and fetch, which accepts a swiss-num and returns a reference to the appropriate object. The second returned value, the locator, only has one method, fetch, which operates exactly the same as that of registry.

To clarify, here’s an example:

> (use-modules (goblins actor-lib cell))
> (define-values (nr nr-locator) (spawn-nonce-registry-and-locator))
> nr
=> #<local-object ^nonce-registry>
> (define chest (spawn ^cell 'gold))
> (define chest-token ($ nr 'register chest))
> chest-token
=> #vu8(<32 random 8-bit unsigned integers>)
> ($ nr 'fetch chest-token)
=> #<local-object ^cell>
> ($ nr-locator 'fetch chest-token)
=> #<local-object ^cell>