3 ms·
Pretty sure you can do this in CL but I'm short on time so I'm not going to figure it out right now. Most of the time I try to get rid of variable names so it
by cess11 3y ago
Pretty sure you can do this in CL but I'm short on time so I'm not going to figure it out right now.
Most of the time I try to get rid of variable names so it seems somewhat strange to invent more than one pointing to the same data structure in RAM, but I'm a simple person that gets confused easily.
- tmtvl 3y agoWith adjustable arrays it's easy: (defun vector-delete! (vector index) "Delete the element at INDEX from the given VECTOR. Destructively modifies the vector. The vector must have a fill-pointer. This is not thread-safe, use at your own risk. Examples: (let* ((x (make-array 4 :fill-pointer 4 :initial-contents '(1 2 3 4))) (y x)) (vector-delete! x 0) y) ;; => #(2 3 4)" (declare (type (Integer 0 *) index) (type Vector vector)) (assert (array-has-fill-pointer-p vector)) (let ((l (length vector))) (assert (< index l)) (let ((removed-element (aref vector index))) (loop :for i :from (1+ index) :below l :do (setf (aref vector (1- i)) (aref vector i))) (decf (fill-pointer vector)) removed-element))) (Granted, it could be done in 6 lines of code, but I'm already cringing at not providing a continuation when calling it with an out-of-bounds index)