Scheme Programmer's Manual
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
Copies the bytes from
source at indices
source-start, …, source-start + k − 1
to consecutive indices in target starting at target-index.
Copies the bytes of bytevector from between start and end
to bytevector to, starting at at.
Returns unspecified values.
(let ((b (u8-list->bytevector '(1 2 3 4 5 6 7 8))))
(bytevector-copy! b 0 b 3 4)
=> (1 2 3 1 2 3 4 8)
(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
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.
The arguments used by R7RS are consistent with SRFI-43 whereas R6RS is
consistent with SRFI-66.
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Implementations need to be careful to handle the case where the source
and target bytevector ranges overlap in memory.
Return to Main Contents
- RETURN VALUES
- APPLICATION USAGE
- SEE ALSO