Next: Procedures, Previous: Pair Data, Up: Non-immediate Datatypes
Vectors, strings, and symbols have some properties in common. They all
have a length, and they all have an array of elements. In the case of a
vector, the elements are SCM
values; in the case of a string or
symbol, the elements are characters.
All these types store their length (along with some tagging bits) in the
car of their header cell, and store a pointer to the elements in
their cdr. Thus, the SCM_CAR
and SCM_CDR
macros
are (somewhat) meaningful when applied to these datatypes.
Return the length of the object x. The result is undefined if x is not a vector, string, or symbol, respectively.
Return a pointer to the array of elements of the vector x. The result is undefined if x is not a vector.
Return a pointer to the characters of x. The result is undefined if x is not a symbol or string, respectively.
There are also a few magic values stuffed into memory before a symbol's characters, but you don't want to know about those. What cruft!
Note that SCM_VECTOR_BASE
, SCM_STRING_CHARS
and
SCM_SYMBOL_CHARS
return pointers to data within the respective
object. Care must be taken that the object is not garbage collected
while that data is still being accessed. This is the same as for a
smob, See Remembering During Operations.