Taylor Venable <tay...@metasyntax.net> writes: > Hi there, I'm writing a piece of code with a web server component, and > part of that being that I want to jump back to the REPL when one hits > ^C. So it would go something like this: > > scheme@(guile-user)> (start-server) > ;;; handling requests > ^C > scheme@(guile-user)> > > What I tried doing was essentially this: > > (call/cc (lambda (k) (sigaction SIGINT (lambda (_) (k))) (start-server)))
Just a couple of notes here. First, continuations usually take an argument: the value which will be the return value of the (call/cc ...) expression. So '(k)' may be wrong. Second, I wonder if you meant (lambda _ ...) instead of (lambda (_) ...). I often use the former when I want a lambda that accepts any number of arguments. > Except *sometimes* when I hit ^C I ended up with an error that stops > the guile program completely, seemingly due to the readline library > that I've enabled in the REPL. When I simplify my test I'm able to > get the same fatal error all the time. [..] > In unknown file: > ?: 0 [catch-closure misc-error "%readline" "readline is not reentrant" () > #f] This suggests to me that the code was already inside readline when you hit ^C. Does (start-server) ever return naturally? If it does, there's a window where it's just returned and the REPL is calling readline to read the next line of input, but the terminal may not have shown the prompt yet. So if you type ^C in that window, the error above would be expected. Alternatively, does the code inside (start-server) ever use readline? Perhaps by mistake it is using '(readline)' instead of '(read-line)' from (ice-9 rdelim)? In this case there'd obviously be loads more chances of seeing the above error. Regards, Neil