From 7ef0dcb6919ded8f19e876b9fbe823c579ec0867 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 16 Jul 2020 21:20:43 -0500 Subject: bugfix in skip-while! --- gtwiwtg.lisp | 14 ++++++++++---- 1 file 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) -- cgit v1.2.3