aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--gtwiwtg.lisp21
2 files changed, 17 insertions, 6 deletions
diff --git a/README.md b/README.md
index 106ec38..c6544e5 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ docstring. Many docstrings include examples of use.
```
-## First, Here's the Action
+## First, Some Action
Here are a few examples to show you what you can do. A more involved
example apears at the end of the document, following the tutorial.
diff --git a/gtwiwtg.lisp b/gtwiwtg.lisp
index ac846bd..00534f5 100644
--- a/gtwiwtg.lisp
+++ b/gtwiwtg.lisp
@@ -60,10 +60,10 @@
;;; Generator Classes ;;;
(a-generator-class range-backed-generator! ()
- (at 0) to (by 1) inclusive (comparator #'<))
+ (at 0) to (by 1) (comparator #'<))
(defmethod has-next-p ((g range-backed-generator!))
- (with-slots (to current comparator by at) g
+ (with-slots (to comparator by at) g
(or (not to)
(funcall comparator
(+ by at)
@@ -162,7 +162,6 @@ If TO is NIL, then the generator produces an infinite sequence.
(if inclusive #'>= #'>))))
(make-instance 'range-backed-generator!
:comparator comparator
- :inclusive inclusive
:at (- from by)
:to to
:by by)))
@@ -183,7 +182,7 @@ of the sequence."
:sequence sequence
:index (1- start))))
-(defun from-thunk-until (thunk &optional (until (constantly nil)) clean-up)
+(defun from-thunk-until (thunk &key (until (constantly nil)) clean-up)
"Creates a generator that produces a series of value by successively
calling (FUNCALL THUNK). The iterator stops whenever (FUNCALL UNTIL)
is non null.
@@ -375,8 +374,10 @@ Error Conditions:
(from-thunk-until
(lambda ()
(apply map-fn (mapcar #'next all-gens)))
+ :until
(lambda ()
(some (complement #'has-next-p) all-gens)) ; when at least one has no next value
+ :clean-up
(lambda ()
(dolist (g all-gens) (stop g))))))
@@ -391,6 +392,8 @@ Error Condition:
(let (on-deck)
(from-thunk-until
(lambda () on-deck) ; consumers always call has-next-p before next
+
+ :until
(lambda ()
(loop
:while (has-next-p gen)
@@ -400,6 +403,8 @@ Error Condition:
(setf on-deck candidate)
(return nil)) ; Don't stop generating, we found one
:finally (return t))) ; Stop generating, we can't find one.
+
+ :clean-up
(lambda ()
(stop gen)))))
@@ -435,6 +440,7 @@ Error Conditions:
(from-thunk-until
(lambda () (next sub-gen))
+ :until
(lambda ()
(loop
:until (has-next-p sub-gen)
@@ -447,7 +453,8 @@ Error Conditions:
;; hence:
(not (or (has-next-p sub-gen)
(has-next-p gen))))
-
+
+ :clean-up
(lambda ()
(stop gen)
(when sub-gen (stop sub-gen)))))))
@@ -510,9 +517,11 @@ Error Conditions:
all-gens)))
(car vals)))
+ :until
(lambda ()
(null all-gens))
+ :clean-up
(lambda ()
(dolist (g all-gens) (stop g))))))
@@ -591,10 +600,12 @@ Caveat:
(t (error "Attempted to get next from a spent generator."))))
+ :until
(lambda ()
(and (not (has-next-p source-generator))
(queue-empty-p local-q)))
+ :clean-up
(lambda ()
(setf (car local-stop) t)
(when (every #'car stop-cells)