Skip to content

Manipulating Bytevectors ​

Bytevectors can be created, copied, and analyzed with the following procedures and C functions.

Scheme Procedure: make-bytevector len [fill] ​

C Function: scm_make_bytevector (len, fill) ​

C Function: scm_c_make_bytevector (size_t len) ​

Return a new bytevector of len bytes. Optionally, if fill is given, fill it with fill; fill must be in the range [-128,255].

Scheme Procedure: bytevector? obj ​

C Function: scm_bytevector_p (obj) ​

Return true if obj is a bytevector.

C Function: int scm_is_bytevector (SCM obj) ​

Equivalent to scm_is_true (scm_bytevector_p (obj)).

Scheme Procedure: bytevector-length bv ​

C Function: scm_bytevector_length (bv) ​

Return the length in bytes of bytevector bv.

C Function: size_t scm_c_bytevector_length (SCM bv) ​

Likewise, return the length in bytes of bytevector bv.

Scheme Procedure: bytevector=? bv1 bv2 ​

C Function: scm_bytevector_eq_p (bv1, bv2) ​

Return #t if bv1 equals bv2—i.e., if they have the same length and contents.

Scheme Procedure: bytevector-fill! bv fill [start [end]] ​

C Function: scm_bytevector_fill_x (bv, fill) ​

Fill positions [start ... end) of bytevector bv with byte fill. start defaults to 0 and end defaults to the length of bv.[1]

Scheme Procedure: bytevector-copy! source source-start target target-start len ​

C Function: scm_bytevector_copy_x (source, source_start, target, target_start, len) ​

Copy len bytes from source into target, starting reading from source-start (an index index within source) and writing at target-start.

It is permitted for the source and target regions to overlap. In that case, copying takes place as if the source is first copied into a temporary bytevector and then into the destination.

Scheme Procedure: bytevector-copy bv ​

C Function: scm_bytevector_copy (bv) ​

Return a newly allocated copy of bv.

C Function: scm_t_uint8 scm_c_bytevector_ref (SCM bv, size_t index) ​

Return the byte at index in bytevector bv.

C Function: void scm_c_bytevector_set_x (SCM bv, size_t index, scm_t_uint8 value) ​

Set the byte at index in bv to value.

Low-level C macros are available. They do not perform any type-checking; as such they should be used with care.

C Macro: size_t SCM_BYTEVECTOR_LENGTH (bv) ​

Return the length in bytes of bytevector bv.

C Macro: signed char * SCM_BYTEVECTOR_CONTENTS (bv) ​

Return a pointer to the contents of bytevector bv.


  1. R6RS only defines (bytevector-fill! bv fill). Arguments start and end are a Guile extension (cf. vector-fill!, string-fill!). ↩︎