4 ms·
In Clojure: possible but ugly. Use destructuring in production instead. (defn make-xrs [n] (if (= n 0) {"ar" first, "dr" rest} (let [last (make-xrs (dec
by rincewind 17y ago
In Clojure: possible but ugly. Use destructuring in production instead.
(defn make-xrs [n]
(if (= n 0) {"ar" first, "dr" rest}
(let [last (make-xrs (dec n))]
(into last (for [[name fun] last [name2 fun2] {"d" rest "a" first}]
[(str name2 name) (comp fun2 fun)])))))
(for [[name fun] (make-xrs 10)]
(eval `(def ~(symbol (str "c" name)) ~fun)))
- philh 17y agoThat lets you write c[ad]{1,10}r, or c[ad]{1,n}r with O(2^n) initialisation time. OP wanted to be able to write c[ad]+r. Also, that eval could be replaced with (untested) (intern *ns* (symbol (str "c" name)) fun)