Hamming distance in Common Lisp

Still needs much work; don’t use this yet. Snippet released under GPL v3.

(defun hamming (x y)
  (labels ((_nor (a b) (not (or a b)))
           (_diff (a b)
             (if (eq a b) 0 1))
           (_hamming (a b c)
             (if (_nor a b)
               (_hamming (rest a)
                 (rest b)
                 (+ c
                   (_diff (car a)
                     (car b)))))))
          (_hamming (coerce x 'list) (coerce y 'list) 0))) ;; probably expect the caller to coerce instead

Leave a Reply

Your email address will not be published. Required fields are marked *