Re: Quick question about SRFI-170 directory-files Lassi Kortela 29 Jul 2019 18:15 UTC
> 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. OK so a version of Chibi's directory-fold... (directory-fold dir kons knil) ... that gets lists instead of individual names. Get all files in the directory: (directory-fold dir append '()) Filter them: (import (srfi 1)) (directory-fold dir (lambda (new-names so-far) (append so-far (filter not-a-dotfile? new-names))) '()) Gather into a hash table: (import (srfi 69)) (directory-fold dir (lambda (new-names ht) (for-each (lambda (name) (hash-table-set! ht name (get-some-info dir name))) new-names) ht) (make-hash-table)) Get only some files: (directory-fold dir (lambda (new-names so-far) (if (>= (length so-far) 10) so-far (append so-far new-names))) '()) Only count the files: (directory-fold dir (lambda (new-names count) (+ count (length new-names))) 0) What do you think?