[ create a new paste ] login | about

Project: programmingpraxis
Link: http://programmingpraxis.codepad.org/Ig82n9QQ    [ raw code | fork ]

programmingpraxis - Scheme, pasted on Nov 1:
; 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")


Create a new paste based on this one


Comments: