Next: , Previous: Pre-Scheme bitwise manipulation, Up: Standard Pre-Scheme environment


9.3.4 Compound data manipulation

Pre-Scheme has somewhat lower-level vector & string facilities than Scheme, with more orientation towards static typing. It also provides a statically typed record facility, which translates to C structs, though not described here, as it is not in the prescheme structure; see Pre-Scheme record types.

— procedure: make-vector length init –> vector
— procedure: vector-length vector –> integer
— procedure: vector-ref vector index –> value
— procedure: vector-set! vector index value –> unit

Vectors in Pre-Scheme are almost the same as vectors in regular Scheme, but with a few differences. Make-vector initializes what it returns with null pointers (see below); it uses the required (unlike Scheme) init argument only to determine the type of the vector: vectors are statically typed; they can contain only values that have the same static type as init. Vector-length is available only at the top level, where calls to it can be evaluated at compile-time; vectors do not at run-time store their lengths. Vectors must also be explicitly deallocated.

Warning: As in C, there is no vector bounds checking at run-time.

— procedure: make-string length –> string
— procedure: string-length string –> integer
— procedure: string-ref string index –> char
— procedure: string-set! string index char –> unit

Strings in Pre-Scheme are the nearly same as strings in R5RS Scheme. The only three differences here are that make-string accepts exactly one argument, strings must be explicitly deallocated, and strings are nul-terminated: string-length operates by scanning for the first ASCII nul character in a string.

Warning: As in C, there is no string bounds checking at run-time.

— procedure: deallocate pointer –> unit

Deallocates the memory pointed to by pointer. This is necessary at the end of a string, vector, or record's life, as Pre-Scheme data are not automatically garbage-collected.

— procedure: null-pointer –> null-pointer
— procedure: null-pointer? pointer –> boolean

Null-pointer returns the distinguished null pointer object. It corresponds with 0 in a pointer context or NULL in C. Null-pointer? returns true if pointer is a null pointer, or false if not.