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

- I would always leave out dot and dot-dot from the results

+1, even for the low-level open/read/close.  If you want . and .. it's easy to add them by hand.
However, sometimes you want them.

Hence the flag.
And there are many other kinds of
files that are useful to leave out also - such as editor backup files,
binary files, empty files, non-regular files, etc.

These, however, are not hidden by ls(1) by default and omitted by glob patterns.  People usually exclude dotfiles when they think of what the contents of a directory are, with the consequence that moving all the contents of a directory requires 'mv * .[^.]* destination" (hopefully no one has a double dotfile).

In essence, dotfiles are a way of attaching arbitrary key-value pairs to directories.  That's not true of binaries and such.

- 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.

John Cowan          http://vrici.lojban.org/~cowan        xxxxxx@ccil.org
If you understand, things are just as they are.
if you do not understand, things are just as they are.