One unanswered question from a few weeks ago was if we should provide a facility on top of open/read/close-directory that deals with very large directories more gracefully than directory-files, which just returns a list.  If so, lots of good examples were referred to, and this snippet might be the best point we got to while discussing it:

From: John Cowan <xxxxxx@ccil.org>
Date: Tuesday, July 30, 2019 1:52 PM

On Mon, Jul 29, 2019 at 1:42 PM Lassi Kortela <xxxxxx@lassi.io> wrote:

[ Resolved dot files issues. ]

- Common Lisp used to have a 'with-directory-iterator' function in some
third-party library. So instead of returning a list of names, it
returned an iterable. For filtering, this could be the best option. A
directory _can_ in principle have 10k files or even more.

It's trivial to transform open-directory into a generator, and then you get the full power of SRFI 158.

+1 for directory-fold, but -1 for returning an arbitrary number of results, which just complicates matters for the users.  You could implement directory-fold on top of a read-many-entries call in C and then do the conversion en masse, though.

Extending the Scheme port system is very involved and implementation-dependent, and I don't want to go there.  Using generators is much better.  I have a little library at <https://bitbucket.org/cowan/r7rs-wg1-infra/src/default/PortOperationsCowan.md> that converts port operations to generators/accumulators.

- Harold