Vectors are functions
A vector is, conceptually, a function from an index to an object and in muSE, a vector is exactly that - a normal function. Here's an example -
(define rgb (mk-vector 3))
Now rgb is a 3-element vector, with all the slots set to (). Here's how to set the three color components -
(rgb 0 255) ; Red
(rgb 1 255) ; Green
(rgb 2 255) ; Blue
To get the green component, for example, you use (rgb 1). If you pass an index out of range, you always get ().
You can create a vector from data using the vector function like this -
(vector 255 255 255)
Other vector manipulation functions are more or less the same as standard Scheme - such as vector-length, list->vector and vector->list.
No comments:
Post a Comment