Experimenting With Spritely Goblins

News

Let’s Try Goblins!

Today we’re going to experiment with Spritely Goblins to learn how it works and see if it would be appropriate to use for a MUD game project that I’m planning to build for the upcoming Spring Lisp Game Jam!

Resources:

Check out using Goblins with Guile Hoot:

The code

Here’s the example code we experimented with. We spent most of the time walking through the Goblins manual!

(use-modules (goblins)
             (goblins vat)
             (fibers)
             (fibers conditions)
             (system repl server))

(define-actor (^sleeper _bcom)
  (lambda ()
    (define sleep-vow
      (spawn-fibrous-vow (lambda () (sleep 3) #t)))
    (on sleep-vow
        (lambda _
          'awake)
        #:promise? #t)))

(define-actor (^hello _bcom)
  (lambda ()
    'hello))

(define a-vat (spawn-vat))
(define sleeper
  (with-vat a-vat
    (spawn ^sleeper)))
(define hello
  (with-vat a-vat
    (spawn ^hello)))

(define b-vat (spawn-vat))
(with-vat b-vat
  (on (<- sleeper)
      (lambda (response)
        (pk 'sleeper-said response)))
  (on (<- hello)
      (lambda (response)
        (pk 'hello-said response))))

;; Start a REPL, use `geiser-connect' to enter it!
(run-server)
Subscribe to the System Crafters Newsletter!
Stay up to date with the latest System Crafters news and updates! Read the Newsletter page for more information.
Name (optional)
Email Address