Vector is a data type not disclosed by the Autodesk. It is somewhat similar to the list, but it saves more memory and operates faster. It can also be converted with the list.
The data structure of LISP list is a linked list, which needs to be traversed from scratch, so the operation speed is slow. Vector doesn't have this limitation and can start from anywhere, so it's faster.
A vector of print will be displayed like this: #4 (1, 2, 3, 4), indicating that the vector has four elements, and the list of elements is in parentheses.
After research, I have basically understood its mechanism. Let's test it here.
I wrote a small program syz-vector.fas, you can operate the vector after loading.
Several related functions:
Vector create a vector
Vector-length gets the length of the vector
list->vector
vector->List
vector-ELT gets an element of the vector
Vector-ELT<- replaces an element of a vector
Vector-swap swaps two elements of a vector
test example:
Command: (vector 1 2 3 4 5)
#5(1 2 3 4 5)
Command: (setq AA (vector 1 2 3 4 5))
#5(1 2 3 4 5)
Command: (vector-length AA)
5
Command: (vector->List AA)
(1 2 3 4 5)
Command: (list->vector '(2 3 4 5))
#4(2 3 4 5)
Command: (vector->ELT AA 3)
4
Command: (vector ELT<- AA 8 3)
8
Command: (print AA)
#5(1 2 3 8 5)
Command: (vector-swap AA 0 3)
#5(8 2 3 1 5)
Command: (vector-swap AA 1 4)
#5(8 5 3 1 2)