Thanks Eli - I'll look into scheme_add_atexit_closer and exit-handler more.<br><br><div class="gmail_quote">On Mon, Mar 23, 2009 at 10:42 PM, Eli Barzilay <span dir="ltr"><<a href="mailto:eli@barzilay.org">eli@barzilay.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">At the Scheme level `exit' will just exit the process, so dynamic wind<br>
etc do nothing. For example,<br>
<br>
(dynamic-wind void exit (lambda () (printf "bye\n")))<br>
<br>
will not do the printout before leaving.<br>
<br>
There is a `scheme_add_atexit_closer' function in the mzscheme api,<br>
which might do what you want, for example:<br>
<br>
(require scheme/foreign)<br>
(unsafe!)<br>
((get-ffi-obj "scheme_add_atexit_closer" #f<br>
(_fun (_fun _scheme _pointer _pointer -> _void)<br>
-> _void))<br>
(lambda (x _1 _2) (printf "bye\n")))<br>
<br>
but this is called for managed objects, so you might need to use some<br>
more of the C api to register your objects. (Or just do whatever you<br>
need, and make sure that there's at least one managed object that will<br>
cause your handler to be called.)<br>
<br>
If you prefer a Scheme solution, then perhaps it is better to change<br>
the exit handler:<br>
<br>
(exit-handler (let ([old (exit-handler)])<br>
(lambda (s) (printf "bye\n") (old s))))<br>
<br>
this will work if you do it when starting your code *and* if you<br>
always exit your program using `exit' (for example, you register an<br>
exception handler to print the error and call `exit' instead of<br>
letting it abort). But if that's what you're doing, you can just as<br>
well write your own `exit' function that will do the cleanup and then<br>
actually exit.<br>
<font color="#888888"><br>
--<br>
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:<br>
<a href="http://www.barzilay.org/" target="_blank">http://www.barzilay.org/</a> Maze is Life!<br>
</font></blockquote></div><br>