(define (character-count filename)
(call-with-input-file
filename
(lambda (source)
(let loop ((count 0)
(ch (read-char source)))
(if (eof-object? ch)
count
(loop (+ count 1) (read-char source)))))))
(define (read-line source)
(let loop ((chars '())
(ch (read-char source)))
(if (char=? ch #\newline)
(apply string (reverse chars))
(loop (cons ch chars) (read-char source)))))
This document is available on the World Wide Web as
http://www.math.grin.edu/~stone/events/scheme-workshop/Friday-answers.html