dynamic list comprehension
Sometimes it's just not enought to set the binding forms at compile time.
(defmacro dyn-for [xs] `(let [;; index set of tupel (input[i], [0..][i]) sym-index# (zipmap (repeatedly (fn [](gensym))) ~xs) ;;alternating collection (index symbol, range, index symbol, range, ..., index symbol, range) keyvals# (reduce #(conj % (first %2) (second %2)) [] sym-index#) ;;for definition fd# (list `for keyvals# (vec (reverse (map first sym-index#))))] (eval fd#)))
consuming a seq of seq like the following
(dyn-for (repeat 2 [:a :b]))
produces this in your very REPL
([:a :a :a] [:b :a :a] [:c :a :a] [:a :b :a] [:b :b :a] [:c :b :a] [:a :c :a] [:b :c :a] [:c :c :a] [:a :a :b] [:b :a :b] [:c :a :b] [:a :b :b] [:b :b :b] [:c :b :b] [:a :c :b] [:b :c :b] [:c :c :b] [:a :a :c] [:b :a :c] [:c :a :c] [:a :b :c] [:b :b :c] [:c :b :c] [:a :c :c] [:b :c :c] [:c :c :c])












