anchor.diff:            :documentation "The start of the iteration, either an index value or integer value to mark the start of iteration")
      (index :initform 0
             :documentation "the current index of the iteration") 
  -   (end :initform -1 :initarg :end
  -        :documentation "The end of the iteration, -1 denotes an infinite iteration, for lists/sequences, the sequence length limits the iteration")
  +   (length :initform -1 :initarg :length
  +        :documentation "The length of the iteration, -1 denotes an infinite iteration, for lists/sequences, the sequence length limits the iteration")
      (increment :initform 1 :initarg :inc
                 :documentation "the increment of the iteration")
      (id :initform #'identity :initarg :id
  
positive.code:    (quiet :initform T :initarg :quiet
            :documentation "Whether to raise an error when iterations are exhausted")
     (cyclic :initform nil :initarg :cyclic
             :documentation "Whether the iteration is cyclic, in case where values are supplied the sequence re-iterated otherwise the iteration resets the index to start")
     (values :initform nil :initarg :values
             :documentation "A list/sequence of values to be iterated")
     (bound-check :initform #'<= :initarg :reverse
                  :documentation "When T, direction of iteration is reversed")
     (comparer :initform #'(lambda(n values) (nth n values))
               :documentation "Function to access to individual members of a values, #'nth for lists, #'elt for others")))
  
  (defmethod reset((iter iterator))
    (with-slots (start index) iter
      (setf index start)))
  
  (defmethod next((iter iterator))
    (with-slots (index end increment id quiet cyclic
                       comparer bound-check values) iter
      (if (or (funcall bound-check index end) (eq end -1))
          (let ((current
                 (funcall id (if values
                                 (funcall comparer index values)
                                 index))))
            (incf index increment)
            current)
          (if cyclic
  
negative.code:      while (and i j)
       collect (cons i j)))
  
  (defmacro make-iterator (&key (start 0) (length -1) (inc 1) (id #'identity) (cyclic nil)
                             (initial-contents ()) (from-end nil) (initial-element nil))
    `(let ((tmp (make-instance 'iterator :start ,start
                               :length (if (null ,initial-contents)
                                           ,length
                                           (1- (length ,initial-contents)))
                               :inc ,inc :id ,id :cyclic ,cyclic
                               :initial-contents ,initial-contents
                               :initial-element ,initial-element)))
       (with-slots (start length index initial-contents increment comparer bound-check) tmp
         (when (not (listp initial-contents))
           (setf comparer #'(lambda(n seq) (elt seq n))))
         (if ,from-end
             (setf start length
                   index length
                   length ,start
                   bound-check #'>=
                   increment (* -1 ,inc))
             (setf index start)))
       tmp))
           
  (defmacro with-iterator((name &key (start 0) (length -1) (increment 1)
                                (initial-contents nil) (id #'identity)) &body body)
    `(let ((,name (make-iterator :start ,start
                                 :length ,length :inc ,increment
                                 :initial-contents ,initial-contents :id ,id)))
       ,@body))
  
  (defmethod to-string ((iter iterator))
    (with-slots (start length increment id quiet initial-contents cyclic) iter
      (format T "start: ~A, length: ~A, quiet: ~A, inc: ~A, cyclic: ~A, initial-contents: ~A ~%"
              start length quiet increment cyclic initial-contents)))
  
  (defun get-sequence-iter-varlist (all-clauses)
    (list
     (loop for clause in all-clauses
        for var-name = (nth 0 clause)
        for tmp = (nth 1 clause)
        for iter-tmp = (if (listp tmp) (eval tmp) tmp)
        for result-tmp = (nth 2 clause)
        collect `(,var-name (next ,iter-tmp) (or (next ,iter-tmp) ,result-tmp)))
     `((some #'null (list ,@(loop for clause in all-clauses collect (car clause)))))))
  
  (defmacro do-sequence-iterators (((var iter &optional result) &rest more-clauses) &body body)
    (let ((all-clauses (cons (list var iter result) more-clauses)))
      `(do ,@(get-sequence-iter-varlist all-clauses)
           ,@body)))
  
  (defmacro do-sequence-iterators* (((var iter &optional result) &rest more-clauses) &body body)
    (let ((all-clauses (cons (list var iter result) more-clauses)))
      `(do* ,@(get-sequence-iter-varlist all-clauses)
            ,@body)))
  
  (defmacro do-sequence-iterator ((var iter &optional result) &body body)
    `(do-sequence-iterators* (,var ,iter ,result)
       ,@body))
  
  (defmacro dosequences* (((var sequence &key result start end from-end)
                           &rest more-clauses) &body body)
    (let* ((tmp-clauses (cons (list var sequence start end from-end result) more-clauses))
           (all-clauses (loop for (var sequence start end from-end result) in tmp-clauses
                           collect `(,var (make-iterator :start (or 0 ,start) :initial-contents ,sequence
                                                         :length ,end :from-end ,from-end) ,result))))
      `(do-sequence-iterators* ,all-clauses
         ,@body)))
  
  (defmacro dosequence ((var sequence :key result start end from-end) &body body)
    `(dosequences* ((,var ,sequence :result ,result :start ,start :end ,end :from-end ,from-end))
       ,@body))
  