Re: Get and set current directory
Marc Feeley 21 Jul 2019 14:24 UTC
I guess I’m missing the use case for this… Are you trying to design something that works only in single-threaded Schemes? In other words you are deliberately ignoring issues with concurrent uses of this construct because there’s no solution?
What is the purpose of this construct? It sets up the current directory of the process (to affect the behavior of external, i.e. C and OS, code)? It implements the concept of “current directory” for Scheme code to use (for example to expand relative filenames)? Only one or both?
Marc
> On Jul 21, 2019, at 9:59 AM, Lassi Kortela <xxxxxx@lassi.io> wrote:
>
>> 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.
>