On Mon, Mar 06, 2017 at 09:48:51PM +0100, Andy Wingo wrote: > On Mon 06 Mar 2017 20:15, Vladimir Zhbanov <vzhba...@gmail.com> writes: > > > OK, put things other ways. I have a GUI app which starts REPL in > > another thread. Is there a way to call a thunk in that REPL from > > the GUI app? Basically, I want it to exit gracefully by calling > > (quit) in the REPL before GUI exits. > > What if, in your GUI app, you call stop-server-and-clients! from (system > repl server) ? That aborts to a prompt to unwind the stack, so it's not > catchable but a dynamic-wind out guard will run. Only really works in > 2.2 tho I think.
Well, I confused things, as I already said, and my first question was incorrect. Really, I have a procedure something like the following: (define (my-repl) (let ((repl (make-repl (current-language) #f)) (history-filename (make-custom-history-filename))) (repl-eval repl `(begin (use-modules (ice-9 session) ; help, apropos and such (system repl command)) ; guile meta-commands (display "Welcome to my REPL!\n" (current-error-port)) (resolve-module '(ice-9 readline)) ;; After resolving that module the variable ;; *features* should contain 'readline. (if (provided? 'readline) (begin (use-modules (ice-9 readline)) ((@ (ice-9 readline) activate-readline)) ((@ (ice-9 readline) read-history) ,history-filename)) (display "Readline is not supported in your configuration.\n") (current-error-port)))) (run-repl repl))) So I don't use repl server here. What I tried so far is to manually save dynamic state in repl: (define ds (current-dynamic-state)) and use it in GUI (with support of guile expression evaluation): (with-dynamic-state ds (lambda () (write-history history-filename))) This is for readline history saving, and works pretty well. So I was thinking to bake something like this into the above code, probably by adding a variable on the repl-eval stage to store initial dynamic state in repl. The problem occured when I started to call (quit) or (throw 'quit) the same way, that is, in the thunk called in with-dynamic-state. It just segfaulted. And my app is tied to 2.0 these days. -- Vladimir