diff options
author | Colin Okay <okay@toyful.space> | 2021-03-14 12:28:01 -0500 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2021-03-14 12:28:01 -0500 |
commit | 7051b2606cc2935edad7f2d2c5b85e79c76e0a7c (patch) | |
tree | 2d2e8ff0985a8db0cf7e58292888761ac04afd81 | |
parent | 225b28dee4a19d50e1e0c85a180b62eb73f170bc (diff) |
speed v memory tradeoff note
-rw-r--r-- | README.md | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -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 |