Re: Quick question about SRFI-170 directory-files
Marc Feeley 29 Jul 2019 18:28 UTC
> On Jul 29, 2019, at 1:42 PM, Lassi Kortela <xxxxxx@lassi.io> wrote:
>
> - 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.
>
Gambit has an open-directory procedure that returns a port whose elements, obtained with read, are the files in the directory. This prevents the memory usage problem of directory-files on large directories. You can view this as a wrapper around opendir/readdir/closedir (and it is actually implemented that way).
Marc
> (let ((dir (open-directory "examples")))
(let loop ()
(let ((x (read dir)))
(if (not (eof-object? x))
(begin
(pretty-print x)
(loop))
(close-port dir)))))
"misc"
"makefile"
"web-server"
"tcltk"
"web-repl"
"README"
"pthread"
"pi"
"ring"
"makefile.in"
"distr-comp"
"Xlib-simple"