From 8f39169531e25eb1513778a43ddfed465fc52a4c Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 11 Mar 2021 09:19:49 -0600 Subject: added cartesian product to readme examples --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 96ccefd..980c0c6 100644 --- a/README.md +++ b/README.md @@ -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 -- cgit v1.2.3