From 7051b2606cc2935edad7f2d2c5b85e79c76e0a7c Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sun, 14 Mar 2021 12:28:01 -0500 Subject: speed v memory tradeoff note --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a6c383..a18d5b9 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,24 @@ example apears at the end of the document, following the tutorial. (1 2 4) (1 2 3) (1 2 3 4)) -```` +``` + +Note: The above is just for demonstration purposes and is much slower +than a version you'd write without generators. Something like: + +``` lisp + +(defun powerset (xs) + (if (null xs) (list nil) + (let ((subsets (powerset (cdr xs)))) + (append subsets + (mapcar (lambda (subset) (cons (car xs) subset)) + subsets))))) +``` + +The "vanilla CL" version is MUCH faster, but may not be possible if +you're generating powersets of very long lists. The trade off, as +usual, is between speed and memory. ### A Kind Of Grep -- cgit v1.2.3