From 1c40b95f65ef7c51fe0a66edd29fa27f2e82ebd3 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 10 Jul 2020 00:30:15 -0500 Subject: added list-backed-generator!, modified seq to it appropriately --- gtwiwtg.lisp | 19 ++++++++++++++++--- 1 file 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 -- cgit v1.2.3