; gasoline mileage log
(define (display1 x)
(let ((x (inexact->exact (floor (* 10 x)))))
(display (quotient x 10))
(display ".")
(display (modulo x 10))))
(define (show-log file-name)
(display "Miles Gals Avg") (newline)
(display "------ ---- ----") (newline)
(with-input-from-file file-name
(lambda ()
(let* ((old (read)) (gals (read)))
(let loop ((old old))
(let* ((new (read)) (gals (read)))
(unless (eof-object? (peek-char))
(display new) (display " ")
(display gals) (display " ")
(display1 (/ (- new old) gals))
(newline)
(loop new))))))))
(show-log "log")