Previous: , Up: Kernel   [Contents][Index]


2.1.4 Live Coding

One of the biggest appeals of any Lisp dialect is the ability to use the “read-eval-print loop” (REPL for short) to build programs iteratively and interactively while the program is running. However, programs that run in an event loop and respond to user input (such as a video game) require special care for this workflow to be pleasant. Chickadee provides no built-in support for live coding, but it’s fairly easy to hook up a special kind of REPL yourself.

First, create a cooperative REPL server (It’s important to use Guile’s cooperative REPL server instead of the standard REPL server in (system repl server) to avoid thread synchronization issues). Then, in the game loop’s update procedure, call poll-coop-repl-server and pass the REPL object. Here is a template to follow:

(use-modules (chickadee)
             (system repl coop-server))

(define repl (spawn-coop-repl-server))

(define (update dt)
  (poll-coop-repl-server repl)
  ...)

(run-game #:update update ...)

To use the REPL, connect to it via port 37146. Telnet will do the trick, but using the Geiser extension for Emacs is by far the best way to develop at the REPL with Guile. Use M-x connect-to-guile to connect to the REPL server.