Skip to content

Instantly share code, notes, and snippets.

@carld
Created October 7, 2016 00:42
Show Gist options
  • Save carld/c90b024b8dca0a51dbf7bbe40ddbe445 to your computer and use it in GitHub Desktop.
Save carld/c90b024b8dca0a51dbf7bbe40ddbe445 to your computer and use it in GitHub Desktop.
cartesian product of lists
(define (product . args)
(if (null? args)
(list '())
(apply append
(map (lambda (rest)
(map (lambda (first)
(cons first rest))
(car args)))
(apply product (cdr args))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment