guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trigger action at exit?


From: Ludovic Courtès
Subject: Re: Trigger action at exit?
Date: Sun, 02 Mar 2008 18:25:36 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Hi,

"John Trammell" <address@hidden> writes:

> After a little searching I've stumbled across "add-hook! exit-hook
> ...", but for the life of me I can't seem to get it to do what I want.
>  Here's a taste of what I'm looking for:
>
>    (define foo (lambda () (display "foo") (newline)))
>    (add-hook! exit-hook foo)
>    (run-hook exit-hook)
>
> I'd like something like this, that doesn't need the explicit
> "run-hook" at the end.  Ideas?

`exit-hook' is only run by the REPL, so it's not useful in programs.

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)

Thanks,
Ludovic.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]