Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(defmacro product [xs dim]
"Creates a dim dimension cartesian product of the xs sequence.
For example (product \"ab\" 3) returns ((a a a) (b a a) (a b a) ...)"
(let [syms (take dim (repeatedly gensym))
seq-expr (vec (interleave syms (repeat xs)))
body-expr (cons 'list syms)]
(list 'for seq-expr body-expr)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment