Next: , Previous: Pair Data, Up: Non-immediate Datatypes


A.2.5.2 Vectors, Strings, and Symbols

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.

— Macro: int SCM_VECTORP (SCM x)

Return non-zero iff x is a vector.

— Macro: int SCM_STRINGP (SCM x)

Return non-zero iff x is a string.

— Macro: int SCM_SYMBOLP (SCM x)

Return non-zero iff x is a symbol.

— Macro: int SCM_VECTOR_LENGTH (SCM x)
— Macro: int SCM_STRING_LENGTH (SCM x)
— Macro: int SCM_SYMBOL_LENGTH (SCM x)

Return the length of the object x. The result is undefined if x is not a vector, string, or symbol, respectively.

— Macro: SCM * SCM_VECTOR_BASE (SCM x)

Return a pointer to the array of elements of the vector x. The result is undefined if x is not a vector.

— Macro: char * SCM_STRING_CHARS (SCM x)
— Macro: char * SCM_SYMBOL_CHARS (SCM x)

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.