Created
November 5, 2010 23:54
-
-
Save kirel/665050 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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