aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColin Okay <cbeok@protonmail.com>2020-07-10 00:30:15 -0500
committerColin Okay <cbeok@protonmail.com>2020-07-10 00:30:15 -0500
commit1c40b95f65ef7c51fe0a66edd29fa27f2e82ebd3 (patch)
tree5b3860f66707b43e9719821f9a4793917742045a
parenta0045daf7a3010ee3ddd50c4363cb201aa0d2622 (diff)
added list-backed-generator!, modified seq to it appropriately
-rw-r--r--gtwiwtg.lisp19
1 files changed, 16 insertions, 3 deletions
diff --git a/gtwiwtg.lisp b/gtwiwtg.lisp
index cb1aad3..b2f86f1 100644
--- a/gtwiwtg.lisp
+++ b/gtwiwtg.lisp
@@ -79,6 +79,16 @@
(incf index)
(elt sequence index)))
+(a-class list-backed-generator! (generator!)
+ list)
+
+(defmethod has-next-p ((g list-backed-generator!))
+ (with-slots (stopped-p list) g
+ (unless stopped-p (consp list))))
+
+(defmethod next ((g list-backed-generator!))
+ (pop (slot-value g 'list)))
+
(a-class thunk-backed-generator! (generator!)
next-p-fn
next-fn
@@ -163,9 +173,12 @@ If TO is NIL, then the generator produces an infinite sequence.
generator. The resulting generator will generate exactly the memebers
of the sequence."
(assert (typep sequence 'sequence))
- (make-instance 'sequence-backed-generator!
- :sequence sequence
- :index (1- start)))
+ (if (consp sequence)
+ (make-instance 'list-backed-generator!
+ :list (nthcdr start sequence))
+ (make-instance 'sequence-backed-generator!
+ :sequence sequence
+ :index (1- start))))
(defun from-thunk-until (thunk &optional (until (constantly nil)) clean-up)
"Creates a generator that produces a series of value by successively