6.6.12.9 Bytevector Procedures in R7RS

The R7RS (Section 6.9) defines a set of bytevector manipulation procedures, accessible with

(use-modules (scheme base))

Of these, make-bytevector, bytevector?, bytevector-length, bytevector-u8-ref and bytevector-u8-set! have the same definition as in R6RS. The procedures listed below either have a different definition in R7RS and R6RS, or are not defined in R6RS.

Scheme Procedure: bytevector arg …

Return a newly allocated bytevector composed of the given arguments. Analogous to list.

(bytevector 2 3 4) ⇒ #vu8(2 3 4)

See also u8-list->bytevector.

Scheme Procedure: bytevector-copy bv [start [end]]

Returns a newly allocated bytevector containing the elements of bv in the range [start ... end). start defaults to 0 and end defaults to the length of bv.

(define bv #vu8(0 1 2 3 4 5))
(bytevector-copy bv) ⇒ #vu8(0 1 2 3 4 5)
(bytevector-copy bv 2) ⇒ #vu8(2 3 4 5)
(bytevector-copy bv 2 4) ⇒ #vu8(2 3)

See also the R6RS version.

Scheme Procedure: bytevector-copy! dst at src [start [end]]

Copy the block of elements from bytevector src in the range [start ... end) into bytevector dst, starting at position at. start defaults to 0 and end defaults to the length of src. It is an error for dst to have a length less than at + (end - start).

See also the R6RS version. With

(use-modules ((rnrs bytevectors) #:prefix r6:)
             ((scheme base) #:prefix r7:))

the following calls are equivalent:

(r6:bytevector-copy! source source-start target target-start len)
(r7:bytevector-copy! target target-start source source-start (+ source-start len))
Scheme Procedure: bytevector-append arg …

Return a newly allocated bytevector whose characters form the concatenation of the given bytevectors arg ...

(bytevector-append #vu8(0 1 2) #vu8(3 4 5))
⇒ #vu8(0 1 2 3 4 5)