Clojure and me has moved.

Monday, June 8, 2009

Linear Interpolation and sorted-map

This post has moved, go to its new location
Sorted collections (with subseq and rsubseq) can help when working with a partition of disjoint intervals, eg when you need to interpolate.
(defn interpolator 
"Takes a coll of 2D points (vectors) and returns
their linear interpolation function."
[points]
(let [m (into (sorted-map) points)]
(fn [x]
(let [[[x1 y1]] (rsubseq m <= x)
[[x2 y2]] (subseq m > x)]
(if x2
(+ y1 (* (- x x1) (/ (- y2 y1) (- x2 x1))))
y1)))))

;; => (map (interpolator [[0 0] [1 1] [3 2] [4 3]]) (range 0 9/2 1/2))
;; (0 1/2 1 5/4 3/2 7/4 2 5/2 3)

Moustache: syntax file and tests

This post has moved, go to its new location
Tests and a hairy syntax file.

Friday, June 5, 2009

Enlive selectors: documented!

This post has moved, go to its new location
Selectors syntax