Question about the repl/workflow

Hello everybody,

So I just started programming in guile. I am using raylib-guile. I have a main while-loop that handles input/drawing the scene:

(define move-blue-cube -15.0)
(while (not (WindowShouldClose))
    ;; input
   (DrawCube (make-Vector3 move-blue-cube 2.5 0.0) 1.0 5.0 32.0 BLUE))

When I run this in the repl, because of the while loop I assume, I cannot then eval (set! move-blue-cube -30.0). So I am wondering is there a way to update the repl when a while loop is running? Or should I rethink on how to organize my code, to take advantage of the repl?

1 Like

Guile has a coop repl for this purpose. I used it for the last lisp game jam.
You can let it output and check for input each time you go through the game loop.

(define-module (game main)
  ...
  #:use-module (system repl coop-server)
  ...
  #:export (launch-game))

(define repl #f)     ; somewhere to store the repl 

(define (load)
  "Load the game initial game state."
  ...
  (set! repl (spawn-coop-repl-server))  ; create the coop repl 
  ...)


(define (update dt)
  "Update the game state."
  (poll-coop-repl-server repl)    ; update the repl and check repl input
  ...
  )

And this allows to do the interactive development stuff. It opens a socket to connect to and allows geiser et al to connect to it.

See Cooperative REPL Servers (Guile Reference Manual) for more details.

2 Likes

Excellent! Thank you, I was really hoping something like this was possible. For anyone wondering here is my final setup:

(use-modules (raylib))
(use-modules (system repl coop-server))
(define repl #f)
(set! repl (spawn-coop-repl-server))
(while (not (WindowShouldClose))
  (poll-coop-repl-server repl)
  ;; logic
  )

and then:

  1. M-x geiser
  2. M-x geiser-eval-buffer
  3. C-u M-x connect-to-guile localhost 37146

I have to say this is pretty awesome- it’s like editing emacs/elisp.

3 Likes