Last active
August 29, 2015 14:18
-
-
Save nasser/b2791c3850069b9faa11 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 sliders) | |
(defmacro slider [l] | |
(let [dashes (vec (repeat l "-"))] | |
`(do ~@(map (fn [i] | |
`(defn | |
~(symbol (clojure.string/join (assoc dashes i "*"))) | |
[] | |
~(/ i (- l 1)))) | |
(range l))))) | |
(defmacro sliders [l] | |
`(do ~@(map (fn [i] `(slider ~i)) (range 2 l)))) | |
(sliders 20) | |
(*-) ;; 0 | |
(-*-) ;; 1/2 | |
(--*) ;; 1 | |
(-----*-) ;; 5/6 | |
(---*---) ;; 1/2 | |
(-----*---------) ;; 5/14 | |
(--*------------) ;; 1/7 | |
(-----------*-----) ;; 11/16 | |
(+ (----*-) | |
(-----*)) ;; 9/5 | |
(- (--*-) | |
(--------*--)) ;; -2/15 | |
(float (--*----)) ;; 0.33333 | |
(float (-----*----)) ;; 0.55555 | |
(float (-----*-----)) ;; 0.5 | |
(float (-----------*-------)) ;; 0.611111111 | |
(float (-*)) ;; 1.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment