Warning: This is the manual of the legacy Guile 2.0 series. You may want to read the manual of the current stable series instead.

Next: , Up: SRFI-4   [Contents][Index]


7.5.5.1 SRFI-4 - Overview

Uniform numeric vectors can be useful since they consume less memory than the non-uniform, general vectors. Also, since the types they can store correspond directly to C types, it is easier to work with them efficiently on a low level. Consider image processing as an example, where you want to apply a filter to some image. While you could store the pixels of an image in a general vector and write a general convolution function, things are much more efficient with uniform vectors: the convolution function knows that all pixels are unsigned 8-bit values (say), and can use a very tight inner loop.

This is implemented in Scheme by having the compiler notice calls to the SRFI-4 accessors, and inline them to appropriate compiled code. From C you have access to the raw array; functions for efficiently working with uniform numeric vectors from C are listed at the end of this section.

Uniform numeric vectors are the special case of one dimensional uniform numeric arrays.

There are 12 standard kinds of uniform numeric vectors, and they all have their own complement of constructors, accessors, and so on. Procedures that operate on a specific kind of uniform numeric vector have a “tag” in their name, indicating the element type.

u8

unsigned 8-bit integers

s8

signed 8-bit integers

u16

unsigned 16-bit integers

s16

signed 16-bit integers

u32

unsigned 32-bit integers

s32

signed 32-bit integers

u64

unsigned 64-bit integers

s64

signed 64-bit integers

f32

the C type float

f64

the C type double

In addition, Guile supports uniform arrays of complex numbers, with the nonstandard tags:

c32

complex numbers in rectangular form with the real and imaginary part being a float

c64

complex numbers in rectangular form with the real and imaginary part being a double

The external representation (ie. read syntax) for these vectors is similar to normal Scheme vectors, but with an additional tag from the tables above indicating the vector’s type. For example,

#u16(1 2 3)
#f64(3.1415 2.71)

Note that the read syntax for floating-point here conflicts with #f for false. In Standard Scheme one can write (1 #f3) for a three element list (1 #f 3), but for Guile (1 #f3) is invalid. (1 #f 3) is almost certainly what one should write anyway to make the intention clear, so this is rarely a problem.


Next: , Up: SRFI-4   [Contents][Index]