aboutsummaryrefslogtreecommitdiffhomepage
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
parent7b35295af03008042f44b222fc8814aecc97e93c (diff)
added with-generator form
-rw-r--r--gtwiwtg.lisp9
-rw-r--r--package.lisp1
2 files changed, 10 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.
diff --git a/package.lisp b/package.lisp
index 9916cf3..061ddb7 100644
--- a/package.lisp
+++ b/package.lisp
@@ -30,6 +30,7 @@
#:truncate!
#:inject!
#:disperse!
+ #:with-generator
#:for
#:fold
#:collect