On Fri, 9 Aug 2002, Michael Sperber [Mr. Preprocessor] wrote:
> >>>>> "SB" == Scheming Bugger <firstname.lastname@example.org> writes:
> SB> My primary question here, in addition to any style issues, is
> SB> whether or not I should be concerned about the use of set!. Is set!
> SB> an indication that I should be looking harder for a solution that
> SB> doesn't have side-effects?
> Probably not in this case: that part of the code looks fine.
The SET! doesn't obfuscate the intent here, but on the other hand there's
a more convenient solution without assignments:
(define (count-recent-files base-dir since-time)
(if (and (file-exists? base-dir)
(fold (lambda (file count)
(cond ((file-directory? file)
(+ count (count-recent-files file since-time)))
((< since-time (file-last-mod file))
(+ 1 count))
I'd say that's a rather typical application of srfi-1's FOLD (built into
scsh). Another option would have been a named loop
(let loop ((count 0) (files (directory-files))) ...)
but explicit recursion isn't that great either.