From a0045daf7a3010ee3ddd50c4363cb201aa0d2622 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 10 Jul 2020 00:21:45 -0500 Subject: reorganizing source file --- gtwiwtg.lisp | 39 ++++++++++++++++++++------------------- 1 file 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) -- cgit v1.2.3