[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Trigger action at exit?
From: |
John Trammell |
Subject: |
Re: Trigger action at exit? |
Date: |
Mon, 3 Mar 2008 15:22:05 -0600 |
On Sun, Mar 2, 2008 at 11:25 AM, Ludovic Courtès <address@hidden> 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
Re: Trigger action at exit?,
John Trammell <=