Next: , Previous: , Up: SRFI-4   [Contents][Index] SRFI-4 - Relation to bytevectors

Guile implements SRFI-4 vectors using bytevectors (see Bytevectors). Often when you have a numeric vector, you end up wanting to write its bytes somewhere, or have access to the underlying bytes, or read in bytes from somewhere else. Bytevectors are very good at this sort of thing. But the SRFI-4 APIs are nicer to use when doing number-crunching, because they are addressed by element and not by byte.

So as a compromise, Guile allows all bytevector functions to operate on numeric vectors. They address the underlying bytes in the native endianness, as one would expect.

Following the same reasoning, that it’s just bytes underneath, Guile also allows uniform vectors of a given type to be accessed as if they were of any type. One can fill a u32vector, and access its elements with u8vector-ref. One can use f64vector-ref on bytevectors. It’s all the same to Guile.

In this way, uniform numeric vectors may be written to and read from input/output ports using the procedures that operate on bytevectors.

See Bytevectors, for more information.