diff options
author | Colin Okay <okay@toyful.space> | 2021-03-11 09:19:49 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2021-03-11 09:19:49 -0600 |
commit | 8f39169531e25eb1513778a43ddfed465fc52a4c (patch) | |
tree | f0b686f99a2e63c1cf913f3155b0e47e1e813461 | |
parent | f92b777c679ebcf01e86667631c03cd5128e0072 (diff) |
added cartesian product to readme examples
-rw-r--r-- | README.md | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -82,6 +82,28 @@ example apears at the end of the document, following the tutorial. ``` + +### Cartesian Products + +``` lisp + +> (defun cartesian-product (list &rest lists) + "A generator for the Cartesian product of a some lists" + (if (null lists) + (map! 'list (seq list)) + (inflate! (lambda (elem) + (map! (lambda (tail) (cons elem tail)) + (apply 'cartesian-product lists))) + (seq list)))) + +> (collect (cartesian-product '(1 2 3) '(a b c) '("foo" "bar"))) +((1 A "foo") (1 A "bar") (1 B "foo") (1 B "bar") (1 C "foo") (1 C "bar") + (2 A "foo") (2 A "bar") (2 B "foo") (2 B "bar") (2 C "foo") (2 C "bar") + (3 A "foo") (3 A "bar") (3 B "foo") (3 B "bar") (3 C "foo") (3 C "bar")) + + +``` + ### A Kind Of Grep ``` lisp |