From: "John Trammell" <johntrammell@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>, guile-user@gnu.org
Subject: Re: Trigger action at exit?
Date: Mon, 3 Mar 2008 15:22:05 -0600 [thread overview]
Message-ID: <68dbb6fe0803031322t1dc981cn97e6c3b53c764aac@mail.gmail.com> (raw)
In-Reply-To: <87ve459gxb.fsf@gnu.org>
On Sun, Mar 2, 2008 at 11:25 AM, Ludovic Courtès <ludo@gnu.org> wrote:
> One possibility is to catch the `quit' exception:
>
> guile> (catch 'quit
> (lambda ()
> ;; the function that may `exit'
> (exit 1))
> (lambda (key . args)
> ;; the handler
> (format #t "quit: ~a~%" args)))
> quit: (1)
>
At first blush this looked like a good answer, but it appears to be
calling the handler at the *beginning* of the script, not the end:
(define index 0)
(define has-plan #f)
(define (cleanup)
(simple-format #t "has-plan: ~a~%" has-plan)
(simple-format #t "1..~a~%" index))
(catch 'quit
(lambda () (exit 1))
(lambda (key . args)
(begin (format #t "in handler~%")
(format #t "key:~a args:~a~%" key args)
(cleanup))))
(set! has-plan #t)
(format #t "fiddle dee dee~%")
; output is:
; in handler
; key:quit args:(1)
; has-plan: #f
; 1..0
; fiddle dee dee
I find it interesting that "quit" appears to be a special key to
"catch", but I can't find it documented anywhere (I did find other
keys documented at
http://home.thezone.net/~gharvey/guile/qdocs/html/qdocs_6.html).
Googling for "guile catch key quit" (plus similar variations on
"exception(s)" and "atexit") brings no enlightenment.
Also various attempts to flush stdout do not affect the output
sequence. Am I doing something wrong? Should this work?
Thanks for the help,
JT
next prev parent reply other threads:[~2008-03-03 21:22 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-29 22:30 Trigger action at exit? John Trammell
2008-03-02 17:25 ` Ludovic Courtès
2008-03-03 20:44 ` Neil Jerram
2008-03-03 21:53 ` Ludovic Courtès
2008-03-03 22:17 ` Neil Jerram
2008-03-04 10:25 ` Ludovic Courtès
2008-03-04 17:03 ` John Trammell
2008-03-05 21:14 ` Neil Jerram
2008-03-03 21:22 ` John Trammell [this message]
2008-03-03 21:40 ` Ludovic Courtès
2008-03-03 22:27 ` John Trammell
2008-03-05 21:27 ` Neil Jerram
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=68dbb6fe0803031322t1dc981cn97e6c3b53c764aac@mail.gmail.com \
--to=johntrammell@gmail.com \
--cc=guile-user@gnu.org \
--cc=ludo@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).