(defpackage :rex-md.sbuff (:use :cl)) (defclass sbuff () ((text :reader sbuff-text :initarg :text :type string :initform (error "text required") :documentation "hold the full text of the text buffer") (idx :reader sbuff-idx :initarg :idx :initform -1 :type integer :documentation "current index of the buffer"))) (defun limit (buf) (length (slot-value buf 'text))) (defmethod next (buf) (with-slots (text idx) buf (unless (>= idx (- (limit buf) 1)) (incf idx) (char text idx)))) ;;; TESTING (format t "hello world"); (defparameter *mybuff* (make-instance 'sbuff :text "bob")) (next *mybuff*) (format t "~a~%" (limit *mubuff*)) (loop for chr = (next *mybuff*) then (next *mybuff*) while (not (null chr)) do (format t "~a~%" chr))