CCing to the list to get it on the record, the question was, how important is it for a generator to continue returning the end of file object once it's finished, the previous version didn't do depending on what your open-/read-/close-directory procedures do:

From: John Cowan <>
Date: Friday, September 06, 2019 4:12 PM

Since it's in the spec for generators, we should follow it.  Here's a revised version:

(define make-directory-files-generator
    ((dir dot-files?) (make-directory-files-generator* dir dot-files?))
    ((dir) (make-directory-files-generator* dir #f))))

(define (make-directory-files-generator* dir dot-files?)
  (let ((dir-obj (open-directory dir dot-files?))
        (eof (eof-object))
        (done #f))
    (lambda ()
      (if done eof
        (let ((f (read-directory dir-obj)))
          (when (eq? f eof)
            (close-directory dir-obj)
            (set! done #t))

This works fine, after testing I've added it in a comment in my Chibi Scheme implementation, which didn't need it since it's automagic FFI close-directory finalizer isn't robust, so I was already keeping track if a dir-obj had been closed.

- Harold