guile-user
[Top][All Lists]
Advanced

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

Re: Trigger action at exit?


From: Neil Jerram
Subject: Re: Trigger action at exit?
Date: Mon, 03 Mar 2008 20:44:28 +0000
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

address@hidden (Ludovic Courtès) writes:

> 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)

In the light of this thread, and another one about atexit in AutoGen,
perhaps we should look at providing a Scheme-level at-exit primitive?
The main point, I think, would be to guarantee that anything
registered by (at-exit ...) or scm_at_exit (...) would run _before_
Guile starts doing its own cleanups.

Regards,
        Neil





reply via email to

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