Here is a better version of diff, better only in the sense that it works on
all files.  But what do I know?  Nothing.

This is Common Lisp.  I was running in SBCL.

(defun my-diff (file1 file2)
  (let ((s1 (open file1 :element-type '(integer 0 255)))
        (s2 (open file2 :element-type '(integer 0 255)))
        (c1 0)
        (c2 0))
    (declare (fixnum c1 c2))
    (loop
     (setq c1 (read-byte s1 nil 256))
     (setq c2 (read-byte s2 nil 256))
     (cond ((and (eql c1 256) (eql c2 256)) (return "no difference")))
     (cond ((eql c1 256) (return "file1 hit eof first")))
     (cond ((eql c2 256) (return "file2 hit eof first")))
     (cond ((eql c1 c2))
           (t (return (format nil
                              "difference at position ~s; c1 = ~s, c2 = ~s."
                              (file-position s1) c1 c2)))))))

Reply via email to