aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColin Okay <cbeok@protonmail.com>2020-07-16 21:20:43 -0500
committerColin Okay <cbeok@protonmail.com>2020-07-16 21:20:43 -0500
commit7ef0dcb6919ded8f19e876b9fbe823c579ec0867 (patch)
treee2bcaff374b5721faeb2b918a6983c834f075716
parent4f97013b90926f9f1369b1802857cd66a1e0c927 (diff)
bugfix in skip-while!
-rw-r--r--gtwiwtg.lisp14
1 files changed, 10 insertions, 4 deletions
diff --git a/gtwiwtg.lisp b/gtwiwtg.lisp
index 43e0274..18b32c4 100644
--- a/gtwiwtg.lisp
+++ b/gtwiwtg.lisp
@@ -564,10 +564,16 @@ Caveat:
- If the generator is infinite, then skip-while! MIGHT never return.
"
(sully-when-clean (list gen))
- (loop :while (and (has-next-p gen)
- (funcall pred (next gen))))
- (setf (dirty-p gen) nil)
- gen)
+ (let ((cached (list nil)))
+ (loop
+ :while (has-next-p gen)
+ :for val = (next gen)
+ :unless (funcall pred val)
+ :do
+ (setf (car cached) val)
+ (return))
+ (setf (dirty-p gen) nil)
+ (concat! (seq cached) gen)))
(defun nfurcate! (count source-generator)