bytevector-copy!(3scm) Scheme Programmer's Manual bytevector-copy!(3scm)

bytevector-copy! - copy bytes between bytevectors

(import (rnrs))                     ;R6RS
(import (rnrs bytevectors))         ;R6RS
(import (scheme base))              ;R7RS

(bytevector-copy! source source-start target target-start k)  ;R6RS
(bytevector-copy! to at from start end)                       ;R7RS

R6RS
Copies the bytes from source at indices source-start, …, source-start + k − 1 to consecutive indices in target starting at target-index.
R7RS
Copies the bytes of bytevector from between start and end to bytevector to, starting at at.

Returns unspecified values.

;; R6RS
(let ((b (u8-list->bytevector '(1 2 3 4 5 6 7 8))))
  (bytevector-copy! b 0 b 3 4)
  (bytevector->u8-list b))
   => (1 2 3 1 2 3 4 8)
;; R7RS
(define a (bytevector 1 2 3 4 5))
(define b (bytevector 10 20 30 40 50))
(bytevector-copy! b 1 a 0 2)
   => #u8(10 1 2 40 50)

This procedure is common in (de)serialization and processing of binary data. In some situations it becomes cumbersome to maintain the indices and bytevector ports are more suitable.

R6RS and R7RS specify very different arguments for these procedures. Note in particular that it's not just a different argument order, the last argument is also different.

This procedure can raise exceptions with the following condition types:
&assertion (R6RS)
The wrong number of arguments was passed, an argument was outside its domain or the byte ranges were not valid with regard to the bytevector lengths.
R7RS
The assertions described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

bytevector-copy(3scm)

R6RS, R7RS

The arguments used by R7RS are consistent with SRFI-43 whereas R6RS is consistent with SRFI-66.

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.

Implementations need to be careful to handle the case where the source and target bytevector ranges overlap in memory.
2021-02-20