Skip to content

Instantly share code, notes, and snippets.

Created November 7, 2011 00:11
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 anonymous/1343842 to your computer and use it in GitHub Desktop.
Save anonymous/1343842 to your computer and use it in GitHub Desktop.
temperature.clj
(temperature-groups 5 5 40)
;; should produce the following function:
(fn [n]
(cond
(<= 5 n 10) :5-10
(<= 10 n 15) :10-15
(<= 15 n 20) :15-20
(<= 20 n 25) :20-25
(<= 25 n 30) :25-30
(<= 30 n 35) :30-35
(<= 35 n 40) :35-40)
(defn temperature-groups [start by end]
(fn [n]
(eval
(list*
(loop [groupings '[cond] from start]
(let [to (+ from by)]
(if (< to end)
(recur (conj groupings `(<= ~from ~n ~to)
(keyword (str from "-" to))) to)
groupings))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment