Re: Get and set current directory Lassi Kortela 21 Jul 2019 13:59 UTC

> has the advantage of allowing dynamic binding for procedures such as open-input-file that need to resolve relative file names

One trick is to have a procedure:

     (with-current-directory "/some/dir"
       (lambda () ...))

So with-current-directory saves the OS's idea of the current directory,
does a chdir() to the desired directory before the thunk and then a
chdir() back to the old one afterwards. There's an unwind-protect so the
chdir() is restored to the old one even on error. Many people use this
pattern in various languages. It simple to implement and nice to use.

Caveat: Eager to hear how the dynamic duo of threads and signals will
ruin this proposal too :) I haven't had to deal with those.