>>>>> "SB" == Scheming Bugger <email@example.com> writes:
SB> ;; Return the number of files in the tree rooted at the specified
SB> ;; base directory that have been modified since the specified date.
SB> ;; Modified directories are not counted.
SB> (define (count-recent-files base-dir since-date)
SB> (if (and (file-exists? base-dir)
SB> (file-directory? base-dir))
SB> (with-cwd base-dir
SB> (let ((count 0))
SB> (for-each (lambda (file)
SB> (if (file-directory? file)
SB> (set! count
SB> (+ count
SB> (if (< since-date (file-last-mod file))
SB> (set! count (+ 1 count)))))
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.
SB> A secondary question: Does it make sense to return #f if the
SB> specified base-dir doesn't exist?
It does, but it would be simpler to just omit the top-level IF and
rely on exception handling to notify you when things go wrong. The
same holds for the example below:
SB> ;; Return the date of the last login of the specified user.
SB> (define (last-login name)
SB> (let ((read-user-file (field-reader (infix-splitter)))
SB> (last-login-time "0"))
SB> (if (file-exists? (user-file-name name))
SB> (call-with-input-file (user-file-name name)
SB> (lambda (port)
SB> (awk (read-user-file port) (record fields) ()
SB> ((equal? (car fields) *last-login-field-name*)
SB> (set! last-login-time (cadr fields)))))))
SB> (string->number last-login-time)))
SB> Here again I found it necessary to use set!. Is there a better
SB> way to use awk? Should I do something different to avoid the
SB> string->number conversion?
Yes; avoid AWK. Here's a quick shot at what I'd write:
(define (last-login name)
(let* ((lines (port->string-list (open-input-file (user-file-name name))))
(find (lambda (fields)
(equal? (car fields) *last-login-field-name*))
(string->number (cadr last-fields))))
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla