Skip to content

Bytevector Procedures in R7RS

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

emacs-lisp
(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.

emacs-lisp
(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.

emacs-lisp
(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

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

the following calls are equivalent:

emacs-lisp
(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 ...

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