aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColin Okay <cbeok@protonmail.com>2020-07-10 00:21:45 -0500
committerColin Okay <cbeok@protonmail.com>2020-07-10 00:21:45 -0500
commita0045daf7a3010ee3ddd50c4363cb201aa0d2622 (patch)
treec1d4f9e71ad85e751fbfe46437992ca5f3f79b80
parent6e604edc77d83b0696ad891dc3afff8209e1e69b (diff)
reorganizing source file
-rw-r--r--gtwiwtg.lisp39
1 files changed, 20 insertions, 19 deletions
diff --git a/gtwiwtg.lisp b/gtwiwtg.lisp
index 657de5b..cb1aad3 100644
--- a/gtwiwtg.lisp
+++ b/gtwiwtg.lisp
@@ -12,23 +12,6 @@
(defgeneric stop (gen)
(:documentation "stops the generator"))
-(eval-when (:compile-toplevel :load-toplevel :execute)
- (defun make-keyword (symb)
- (read-from-string (format nil ":~a" symb))))
-
-;;; Utility Class Builder ;;;
-
-(defmacro a-class (name supers &rest slots)
- `(defclass ,name ,supers
- ,(mapcar (lambda (def)
- (if (consp def)
- `(,(car def)
- :initarg ,(make-keyword (car def))
- :initform ,(second def))
- `(,def :initarg ,(make-keyword def)
- :initform nil)))
- slots)))
-
;;; Base Generator Class ;;;
(defclass generator! ()
@@ -48,6 +31,23 @@
(defun make-dirty (g) (setf (dirty-p g) t))
+;;; Utility Class Builder ;;;
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ (defun make-keyword (symb)
+ (read-from-string (format nil ":~a" symb))))
+
+(defmacro a-class (name supers &rest slots)
+ `(defclass ,name ,supers
+ ,(mapcar (lambda (def)
+ (if (consp def)
+ `(,(car def)
+ :initarg ,(make-keyword (car def))
+ :initform ,(second def))
+ `(,def :initarg ,(make-keyword def)
+ :initform nil)))
+ slots)))
+
;;; Generator Classes ;;;
(a-class range-backed-generator! (generator!)
@@ -158,16 +158,15 @@ If TO is NIL, then the generator produces an infinite sequence.
"Shorthand for (RANGE :TO N)"
(range :to n))
-
(defun seq (sequence &key (start 0))
"Turns a sequecne (a list, vector, string, etc) into a
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)))
-
(defun from-thunk-until (thunk &optional (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)
@@ -179,6 +178,8 @@ consumer such as FOR, FOLD, COLLECT, etc.
By default, UNTIL is the function (CONSTANTLY NIL). I.e. it will
generate forever."
+ (assert (and (every #'functionp (list thunk until))
+ (or (null clean-up) (functionp clean-up))))
(make-instance 'thunk-backed-generator!
:stop-fn clean-up
:next-p-fn (complement until)