I'm teaching myself Scheme by using scsh to write some shell
scripts that I'd normally write in Perl. One advantage of scsh that
I've found already is that other people are much less likely to modify
(and break) my scripts.
While I have a grasp of the language, no one I work with knows
Scheme, so I don't have the opportunity to learn the idioms of Scheme
to the same extent that I understand those of C++ or Java. To that
end, I'd appreciate any comments anyone might have regarding my
implementation of the following two functions.
;; Return the number of files in the tree rooted at the specified
;; base directory that have been modified since the specified date.
;; Modified directories are not counted.
(define (count-recent-files base-dir since-date)
(if (and (file-exists? base-dir)
(let ((count 0))
(for-each (lambda (file)
(if (file-directory? file)
(if (< since-date (file-last-mod file))
(set! count (+ 1 count)))))
My primary question here, in addition to any style issues, is
whether or not I should be concerned about the use of set!. Is set!
an indication that I should be looking harder for a solution that
doesn't have side-effects?
A secondary question: Does it make sense to return #f if the
specified base-dir doesn't exist?
;; Return the date of the last login of the specified user.
(define (last-login name)
(let ((read-user-file (field-reader (infix-splitter)))
(if (file-exists? (user-file-name name))
(call-with-input-file (user-file-name name)
(awk (read-user-file port) (record fields) ()
((equal? (car fields) *last-login-field-name*)
(set! last-login-time (cadr fields)))))))
Here again I found it necessary to use set!. Is there a better
way to use awk? Should I do something different to avoid the
Thanks for your time.