配列の先頭または末尾から要素を取りだす - lisp-cookbook-ja/common-lisp GitHub Wiki

配列

配列の先頭または末尾から要素を取りだす

フィルポインタ付きのベクタは vector-pop で末尾から要素を取り出すことができ、取り出した要素の分ベクタは縮みます。

(let ((v (make-array 5 :adjustable T
                       :fill-pointer 5
                       :initial-contents '(1 2 3 4 5))))
  (list (vector-pop v)
        (vector-pop v)
        (vector-pop v)
        v))
;=> (5 4 3 #(1 2))

先頭から取り出したい場合は、自作することになるでしょう。FIXME

(defun vector-pop-front (vec)
  (prog1 (aref vec 0)
         (replace vec vec :start2 1)
         (decf (fill-pointer vec))))

(let ((v (make-array 5 :adjustable T
                       :fill-pointer 5
                       :initial-contents '(1 2 3 4 5))))
  (vector-pop-front v) ;=> 1
  v)
;=> #(2 3 4 5)