# Question about the repl/workflow

**URL:** <https://forum.systemcrafters.net/t/question-about-the-repl-workflow/850>\
**Category:** Programming\
**Tags:** guile\
**Created:** [July 10, 2024, 4:29am UTC](https://forum.systemcrafters.net/t/question-about-the-repl-workflow/850 "2024-07-10T04:29:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamtired](https://avatars.discourse-cdn.com/v4/letter/i/46a35a/32.png) [@iamtired](https://forum.systemcrafters.net/u/iamtired)\
**Post date:** [July 10, 2024, 4:29am UTC](https://forum.systemcrafters.net/t/question-about-the-repl-workflow/850/1 "2024-07-10T04:29:46Z")

</div>

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:

```guile
(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?

---

<div class="post-metadata">

**Author:** ![snamellit](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/snamellit/32/101_2.png) [@snamellit](https://forum.systemcrafters.net/u/snamellit)\
**Post date:** [July 10, 2024, 10:20pm UTC](https://forum.systemcrafters.net/t/question-about-the-repl-workflow/850/2 "2024-07-10T22:20:20Z")

</div>

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.

```auto
(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)](https://www.gnu.org/software/guile/manual/html_node/Cooperative-REPL-Servers.html) for more details.

---

<div class="post-metadata">

**Author:** ![iamtired](https://avatars.discourse-cdn.com/v4/letter/i/46a35a/32.png) [@iamtired](https://forum.systemcrafters.net/u/iamtired)\
**Post date:** [July 11, 2024, 12:19pm UTC](https://forum.systemcrafters.net/t/question-about-the-repl-workflow/850/3 "2024-07-11T12:19:48Z")

</div>

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

```lisp
(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.
