Skip to content

Instantly share code, notes, and snippets.

@kirel
Created November 5, 2010 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirel/665050 to your computer and use it in GitHub Desktop.
Save kirel/665050 to your computer and use it in GitHub Desktop.
(ns similar)
(defprotocol Similar
"Similarity"
(sim [a b] "if a and b are similar return true"))
(def nsim (complement sim))
(def delta 1e-10)
(extend-protocol Similar
java.lang.Number
(sim [a b] (< (abs (- a b)) delta))
clojure.lang.ISeq
(sim [a b]
(and (= (count a) (count b)) (every? identity (map sim a b)))
)
clojure.lang.PersistentVector
(sim [a b] (sim (seq a) (seq b)))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment