Created
November 7, 2011 00:11
-
-
Save anonymous/1343842 to your computer and use it in GitHub Desktop.
temperature.clj
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
(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