aboutsummaryrefslogtreecommitdiffhomepage
path: root/gtwiwtg.lisp
diff options
context:
space:
mode:
authorColin Okay <cbeok@protonmail.com>2020-07-30 08:30:17 -0500
committerColin Okay <cbeok@protonmail.com>2020-07-30 08:30:17 -0500
commit571ae6bfdb3191dda97892bc8b3112958c83a84a (patch)
tree06bad5d911c3e7430439f66bb4caa097f5573aab /gtwiwtg.lisp
parent7b35295af03008042f44b222fc8814aecc97e93c (diff)
added with-generator form
Diffstat (limited to 'gtwiwtg.lisp')
-rw-r--r--gtwiwtg.lisp9
1 files changed, 9 insertions, 0 deletions
diff --git a/gtwiwtg.lisp b/gtwiwtg.lisp
index 83f7cf5..6f0f6f3 100644
--- a/gtwiwtg.lisp
+++ b/gtwiwtg.lisp
@@ -749,6 +749,15 @@ This is sort of the opposite of INTERSPERSE!."
;;; CONSUMERS
+(defmacro with-generator ((var gen) &body body)
+ "Use this if you absolutely must manually call NEXT and
+HAS-NEXT-P. It will ensure that the generator bound to VAR will be
+stopped and cleaned up properly."
+ `(let ((,var ,gen))
+ (assert (typep ,var 'gtwiwtg::generator!))
+ (unwind-protect (progn ,@body)
+ (stop ,var))))
+
(defmacro for (var-exp gen &body body)
"The basic generator consumer.