From 5e11ca9b467f7cd058864e6a21586edbaf22957e Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sun, 14 Mar 2021 11:57:25 -0500 Subject: added subset eg to readme --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 980c0c6..f68fc3f 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,35 @@ example apears at the end of the document, following the tutorial. ``` +### Subsets + +``` lisp + +(defun all-subsets (list) + (if (null list) (seq (list nil)) + (concat! (all-subsets (cdr list)) + (map! (lambda (sub) (cons (car list) sub)) + (all-subsets (cdr list)))))) + +> (collect (all-subsets '())) +(NIL) + +> (collect (all-subsets '(1))) +(NIL (1)) + +> (collect (all-subsets '(1 2))) +(NIL (2) (1) (1 2)) + +> (collect (all-subsets '(1 2 3))) +(NIL (3) (2) (2 3) (1) (1 3) (1 2) (1 2 3)) + +> (collect (all-subsets '(1 2 3 4))) +(NIL (4) (3) (3 4) (2) (2 4) (2 3) (2 3 4) (1) (1 4) (1 3) (1 3 4) (1 2) + (1 2 4) (1 2 3) (1 2 3 4)) + + +```` + ### A Kind Of Grep ``` lisp -- cgit v1.2.3