Skip to content

Instantly share code, notes, and snippets.

Created March 22, 2011 06:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
(defn min-cps [args ret]
(ret (apply min args)))
(defn plus-cps [args ret]
(ret (apply + args)))
(defn multiply-cps [args ret]
(ret (apply * args)))
(defn equals-cps [a b ret]
(ret (= a b)))
(defn toplevel-levenshtein-cps-memoize [x y]
(let [mem (atom {})]
(letfn [(levenshtein-cps-memoize-rec
[x y ret]
(if-let [e (find @mem (list x y))]
#(ret (val e))
(empty? x) #(ret (count y))
(empty? y) #(ret (count x))
(rest x) (rest y)
(fn [levenstein-change]
(swap! mem assoc (list (rest x) (rest y)) levenstein-change)
(list levenstein-change (toplevel-change-cost (first x) (first y)))
(fn [last-addend]
x (rest y)
(fn [levenstein-addition]
(swap! mem assoc (list x (rest y)) levenstein-addition)
(list levenstein-addition 1)
(fn [middle-addend]
(rest x) y
(fn [levenstein-deletion]
(swap! mem assoc (list (rest x) y) levenstein-deletion)
(list levenstein-deletion 1)
(fn [first-addend]
(min-cps (list first-addend middle-addend last-addend) ret)))))))))))))))))))]
(trampoline levenshtein-cps-memoize-rec x y identity))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment