* Q about interrupt and catch
@ 2017-06-11 17:50 Mike Gran
2017-06-12 8:26 ` Thien-Thi Nguyen
2017-06-13 5:24 ` Alex Vong
0 siblings, 2 replies; 3+ messages in thread
From: Mike Gran @ 2017-06-11 17:50 UTC (permalink / raw)
To: guile-user
Hi all,
This is probably a simple question, but, I can't figure it out.
I have a program with a big main loop like this
(while #t
(let ((c (read-char port)))
(cond
... many different possible operations, depending on c
)))
I want to make it so, when the program receives a SIGINT, it aborts
the operation in progress and restarts this big main loop.
Any hints?
Thanks,
Mike Gran
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Q about interrupt and catch
2017-06-11 17:50 Q about interrupt and catch Mike Gran
@ 2017-06-12 8:26 ` Thien-Thi Nguyen
2017-06-13 5:24 ` Alex Vong
1 sibling, 0 replies; 3+ messages in thread
From: Thien-Thi Nguyen @ 2017-06-12 8:26 UTC (permalink / raw)
To: guile-user
[-- Attachment #1.1: Type: text/plain, Size: 275 bytes --]
() "Mike Gran" <spk121@yahoo.com>
() Sun, 11 Jun 2017 10:50:49 -0700
I want to make it so, when the program receives a SIGINT, it
aborts the operation in progress and restarts this big main
loop.
Use ‘sigaction’ and a periodic check. For example:
[-- Attachment #1.2: foo --]
[-- Type: application/x-scheme, Size: 733 bytes --]
[-- Attachment #1.3: Type: text/plain, Size: 438 bytes --]
This does not restart the big main loop, but it does show how to
integrate ‘sigaction’ into normal control flow. Mod to taste...
--
Thien-Thi Nguyen -----------------------------------------------
(defun responsep (query)
(pcase (context query)
(`(technical ,ml) (correctp ml))
...)) 748E A0E8 1CB8 A748 9BFA
--------------------------------------- 6CE4 6703 2224 4C80 7502
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Q about interrupt and catch
2017-06-11 17:50 Q about interrupt and catch Mike Gran
2017-06-12 8:26 ` Thien-Thi Nguyen
@ 2017-06-13 5:24 ` Alex Vong
1 sibling, 0 replies; 3+ messages in thread
From: Alex Vong @ 2017-06-13 5:24 UTC (permalink / raw)
To: Mike Gran; +Cc: guile-user
[-- Attachment #1.1: Type: text/plain, Size: 717 bytes --]
"Mike Gran" <spk121@yahoo.com> writes:
> Hi all,
>
> This is probably a simple question, but, I can't figure it out.
>
> I have a program with a big main loop like this
>
> (while #t
> (let ((c (read-char port)))
> (cond
> ... many different possible operations, depending on c
> )))
>
> I want to make it so, when the program receives a SIGINT, it aborts
> the operation in progress and restarts this big main loop.
>
> Any hints?
>
> Thanks,
> Mike Gran
This is an interesting question. I come up with a solution using the
reset/shift operators. This is the first time I use delimited
continuation. The script is in the attachment. You can run
'chmod +x main-loop.scm' to make the script executable.
[-- Attachment #1.2: main-loop.scm --]
[-- Type: application/octet-stream, Size: 438 bytes --]
#!/bin/sh
#!/usr/bin/guile -*- Scheme -*-
# ; Portability hack to find an interpreter and get Emacs in the right mode.
exec guile -e main "$0"
!#
(use-modules (ice-9 control))
(define (main-loop)
(let ((c (read-char)))
(if (not (eof-object? c))
(write-char c))
(main-loop)))
(define main
(lambda _
(reset (sigaction SIGINT
(lambda _
(shift _ (main-loop))))
(main-loop))))
[-- Attachment #1.3: Type: text/plain, Size: 14 bytes --]
Cheers,
Alex
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-06-13 5:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-11 17:50 Q about interrupt and catch Mike Gran
2017-06-12 8:26 ` Thien-Thi Nguyen
2017-06-13 5:24 ` Alex Vong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).