joaotavora / sly

Sylvester the Cat's Common Lisp IDE
1.26k stars 142 forks source link

sly-mrepl-sync and game loops #368

Open mfiano opened 3 years ago

mfiano commented 3 years ago

If I follow the instructions in 8.4 of the manual to build Sly's REPL into a game loop, if I issue sly-mrepl-sync from a Lisp buffer to switch the package of the REPL, when the game loop is exited, the REPL's package gets reverted back to before sly-mrepl-sync was issued. Is this expected behavior? Can I somehow alter this to make sly-mrepl-sync persistent?

joaotavora commented 3 years ago

Michael Fiano notifications@github.com writes:

If I follow the instructions in 8.4 of the manual to build Sly's REPL into a game loop, if I issue sly-mrepl-sync from a Lisp buffer to switch the package of the REPL, when the game loop is exited, the REPL's package gets reverted back to before sly-mrepl-sync was issued. Is this expected behavior? Can I somehow alter this to make sly-mrepl-sync persistent?

I can't reproduce this. Here's a transcript:

CL-USER> (defun my-repl-aware-game-loop () (loop initially (princ "Starting our game") (slynk-mrepl:send-prompt) for i from 0 do (with-simple-restart (abort "Skip rest of this game loop iteration") (when (zerop (mod i 10)) (fresh-line) (princ "doing high-priority 3D game loop stuff") (force-output)) (sleep 0.1) ;; When you're ready to serve a potential waiting ;; REPL request, just do this non-blocking thing: (with-simple-restart (abort "Abort this game REPL evaluation") (slynk:process-requests t))))) MY-REPL-AWARE-GAME-LOOP CL-USER> (my-repl-aware-game-loop) Starting our game doing high-priority 3D game loop stuff

doing high-priority 3D game loop stuff doing high-priority 3D game loop stuff doing high-priority 3D game loop stuff doing high-priority 3D game loop stuff doing high-priority 3D game loop stuff CL-USER> ; Synched package to SLYNK-COMPLETION and directory to /home/capitaomorte/Source/Emacs/sly/slynk/ SLYNK-COMPLETION>

Now I press C-c C-c and select "Return to SLY's top level"

; Evaluation aborted on T SLYNK-COMPLETION> package

SLYNK-COMPLETION>

As you can see, I stay in the SLYNK-COMPLETION package.

mfiano commented 3 years ago

I cannot reproduce it like that either, however:

(defvar *running-p* t)

(defun my-repl-aware-game-loop ()
  (loop initially
    (princ "Starting our game")
    (slynk-mrepl:send-prompt)
        while *running-p*
        for i from 0
        do (with-simple-restart (abort "Skip rest of this game loop iteration")
             (when (zerop (mod i 10))
               (fresh-line)
               (princ "doing high-priority 3D game loop stuff")
               (force-output))
             (sleep 0.1)
             ;; When you're ready to serve a potential waiting
             ;; REPL request, just do this non-blocking thing:
             (with-simple-restart (abort "Abort this game REPL evaluation")
               (slynk:process-requests t)))))

Then set *running-p* to NIL as the loop is running to terminate it.

mfiano commented 3 years ago

@joaotavora Were you able to reproduce with the above? Just wondering, and no rush on a solution or anything. It has plagued me for a couple years and is only a minor annoyance. I can deal with another couple :)

joaotavora commented 3 years ago

Sorry. I didn't look at it. I probably can reproduce it, yes. I'll look at it later, unless you beat me to it.