Skip to content

Instantly share code, notes, and snippets.

@nasser
Last active August 29, 2015 14:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasser/b2791c3850069b9faa11 to your computer and use it in GitHub Desktop.
Save nasser/b2791c3850069b9faa11 to your computer and use it in GitHub Desktop.
(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