Let’s say that I create a vector/array in Scheme:
(let* ((x #(1 2 3)))
(list-ref x 0)) ; returns error
What syntax or function can I use in the place of that list-ref to get 1?
EDIT: I’m using Script-Fu with GIMP 2.8, where array-ref doesn’t seem to work.
The expression
(define v '#(1 2 3))is shorthand for creating a new vector, in standard Scheme it’s equivalent to this:Or this:
Once a vector is created (using any of the mentioned procedures), the correct way to access an element in a vector is by calling the
vector-refprocedure – clearly, because it’s a vector and not a list of elements:In the previous expression,
vis the vector and0the index whose element we want to retrieve. Take a look at the documentation for a more detailed explanation of the procedures outlined above.