Re: Quick question about SRFI-170 directory-files
Lassi Kortela 29 Jul 2019 18:02 UTC
> - A more general alternative would be a user-supplied filter procedure.
> - Common Lisp used to have a 'with-directory-iterator' function
> In fact, Chibi has a directory-fold procedure:
The real genius of Go's Readdir function just dawned on me:
<https://golang.org/pkg/os/#File.Readdir>
"Readdir reads the contents of the directory associated with file and
returns a slice of up to n [entries] in directory order. Subsequent
calls on the same file will yield further FileInfos."
So you can call it in a loop to get more files. If you call it with a
value of n=1 it works like classic Unix readdir() returning one entry at
a time. If you call it with n=1000 it (hopefully) gets everything at once.
In Scheme we could go even further and leave out the user-supplied 'n'
argument. The implementation could choose how many entries it returns at
one time, according to whatever is most convenient for FFI and GC.
FWIW, Posix has now standardized fdopendir():
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdopendir.html>.
The version of opendir() that works on an fd that you have open()ed first.