From 571ae6bfdb3191dda97892bc8b3112958c83a84a Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Thu, 30 Jul 2020 08:30:17 -0500 Subject: added with-generator form --- gtwiwtg.lisp | 9 +++++++++ package.lisp | 1 + 2 files changed, 10 insertions(+) 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 -- cgit v1.2.3