(below n)

n

below

interval

(map 'vector 'list #(a b c d e) (below 3))

(map 'list '1+ (interval 20 25))

;;; Interval sequence class (defclass interval-sequence (sequence standard-object) ((minimum :reader minimum :initform 0 :initarg :minimum) (length :reader sequence:length :initarg :length))) ;;; Constructors (defun below (n) (unless (>= n 0) (error 'type-error :datum n :expected-type '(integer 0))) (make-instance 'interval-sequence :length n)) (defun interval (min max) (unless (<= min max) (error "Interval minimum must be less than or equal to maximum")) (make-instance 'interval-sequence :minimum min :length (- max min))) ;;; Core sequence protocol (defmethod sequence:elt ((interval interval-sequence) index) (with-slots (minimum length) interval (unless minimum (error "Attempt to read from an uninitialized interval")) (when (or (< index 0) (>= index length)) (error 'type-error :datum index :expected-type `(integer 0 ,(1- length)))) (+ index minimum))) (defmethod (setf sequence:elt) (new-value (interval interval-sequence) index) (with-slots (minimum length) interval (cond ((or (< index 0) (>= index length)) (error 'type-error :datum index :expected-type `(integer 0 ,(1- length)))) ((null minimum) (setf minimum (- new-value index)) new-value) ((/= new-value (+ minimum index)) (error "Incompatible setf of interval element - expected ~A, got ~A" (+ minimum index) new-value)) (t new-value)))) (defmethod sequence:adjust-sequence ((interval interval-sequence) length &key initial-element initial-contents) (declare (ignore interval length initial-element initial-contents)) (error "Interval sequences are immutable")) (defmethod sequence:make-sequence-like ((interval interval-sequence) length &key (initial-element nil iep) (initial-contents nil icp)) (declare (ignore initial-element initial-contents)) (when (or iep icp) (error "Can't create intervals using initial-element/initial-contents.")) (make-instance 'interval-sequence :minimum nil :length length))

(setf elt)

(setf elt)

(- newvalue index)

map

(map 'interval-sequence (lambda (x) (+ x 7)) (below 5))

remove

remove

delete