LINUX.ORG.RU

История изменений

Исправление lovesan, (текущая версия) :

Вот тебе delete функция впридачу

(defun vector-delete (vector index)
  (declare (type (array * (*)) vector)
           (type (integer 0 #.array-total-size-limit) index))
  "Removes an element from the VECTOR at an INDEX.
The VECTOR must be an adjustable one-dimensional array with a fill pointer."
  (let ((fp (fill-pointer vector)))
    (when (or (< index 0)
              (>= index fp))
      (error 'type-error :datum index
                         :expected-type `(integer 0 ,(1- fp))))
    (let ((element (aref vector index))
          (element-type (array-element-type vector)))
      ;; to prevent memory leak
      (setf (aref vector index) (case element-type
                                  ((base-char character) (code-char 0))
                                  (long-float 0.0l0)
                                  (double-float 0.0d0)
                                  (single-float 0.0f0)
                                  (short-float 0.0s0)
                                  (t 0)))
      (replace vector vector :start1 index :start2 (1+ index))
      (decf fp)
      (setf (fill-pointer vector) fp)
      (values element vector))))

Исходная версия lovesan, :

Вот тебе delete функция впридачу


(defun vector-delete (vector index)
  (declare (type (array * (*)) vector)
           (type (integer 0 #.array-total-size-limit) index))
  "Removes an element from the VECTOR at an INDEX.
The VECTOR must be an adjustable one-dimensional array with a fill pointer."
  (let ((fp (fill-pointer vector)))
    (when (or (< index 0)
              (>= index fp))
      (error 'type-error :datum index
                         :expected-type `(integer 0 ,(1- fp))))
    (let ((element (aref vector index)))
      ;; to prevent memory leak
      (setf (aref vector index) (coerce 0 (array-element-type vector)))
      (replace vector vector :start1 index :start2 (1+ index))
      (setf (fill-pointer vector) (1- fp))
      (values element vector))))