Next: , Up: Vats   [Contents][Index]


5.2.1 Vats overview

In order to start programming with Goblins, you will need to boot up a vat somewhere. In general, Goblins uses Fibers to implement vats. However, you can also roll your own vats should you have “unusual” event loop needs (see make-vat).

> (define my-vat (spawn-vat))
> my-vat
=> #<vat izvD0DJT>

Running spawn-vat returns a vat object. Code can be run within the context of a vat using the call-with-vat procedure. This is useful for bootstrapping vats or hacking at the REPL:

> (define my-vat (spawn-vat))
> (call-with-vat my-vat
   (lambda ()
     (define alice (spawn ^greeter "Alice"))
     ($ alice "Bob")))
=> "Hello Alice, my name is Bob!"

For convenience, the with-vat macro can be used instead of call-with-vat. Here’s the above example rewritten to use with-vat:

> (define my-vat (spawn-vat))
> (with-vat my-vat
   (define alice (spawn ^greeter "Alice"))
   ($ alice "Bob"))
=> "Hello Alice, my name is Bob!"

You can also use the vat-halt! procedure to stop the vat, and vat-running? to check its status:

> (vat-halt! my-vat)
> (vat-running? my-vat)
=> #f

NOTE: In the future, we would like vats to automatically halt when no more references exist and thus the vat can do no more work. The Racket version of vats works this way; it would be good for the Guile version to do the same. In the meanwhile, you’ll need to call vat-halt! manually.