Skip to content

Instantly share code, notes, and snippets.

@sztamas
Last active December 22, 2015 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sztamas/6421685 to your computer and use it in GitHub Desktop.
Save sztamas/6421685 to your computer and use it in GitHub Desktop.
(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