You have the correct diagnosis. However, this is not even a question of literal data (for example, (list 1 2 3) vs. '(1 2 3) ) compared with the modified data. This means that the vector has a fill indicator . The documentation for vector-push and vector-push-extend says that the vector argument is a vector with a fill pointer. You will get a similar error with non-literal arrays that don't have a fill pointer, for example:
(let ((v (make-array 3))) (vector-push nil v))
All you have to do is make sure that you create a vector with a fill pointer and large enough to hold what you click:
(let ((v (make-array 2 :fill-pointer 0))) (print v) (vector-push 'xv) (print v) (vector-push 'yv) (print v) (vector-push 'zv) (print v))
vector-push does not configure the array, so you are not getting z in a vector from the final vector-push :
#()
If you make the vector adjustable and use vector-push-extend , you can get a larger array:
(let ((v (make-array 2 :adjustable t :fill-pointer 0))) (print v) (vector-push 'xv) (print v) (vector-push 'yv) (print v) (vector-push-extend 'zv) (print v)) #() #(X) #(XY) #(XYZ)
Using the type of the character element, you will do this with strings:
(let ((v (make-array 2 :element-type 'character :adjustable t :fill-pointer 0))) (print v) (vector-push #\xv) (print v) (vector-push #\yv) (print v) (vector-push-extend #\zv) (print v)) "" "x" "xy" "xyz"
source share