Accessing vectors in common lisp

1.7k views Asked by At
(setf vec (make-array 4 :initial-element nil))
(svref vec 0)

In the above snippet we create a vector of length 4 and access its elements by (svref vec ).

(vector 1 2 3 4 5)

In the above snippet we create a vector of length 5 using vector function. How do we access the elements of this vector? How svref is used for this vector?

1

There are 1 answers

0
Svante On

The generic vector reference function is aref, the same as for all other arrays.

Svref is only for simple vectors, i. e. vectors with element-type t, not adjustable, no fill-pointer, not displaced.

By the way, vector does produce a simple vector, so svref should work for your second example, too.

Other issues:

  • I guess you mean :initial-element.
  • No need to quote number literals, they evaluate to themselves.