bytevector-copy!(3scm)
π bytevector-copy!(3scm) β the Scheme Programmer's Manual, but make it cute π
okay bestie, so this page lives in the Scheme Programmer's Manual and it's all about bytevector-copy! β the little icon that copies bytes between bytevectors β¨
πΈ NAME πΈ
bytevector-copy! β copy bytes between bytevectors, no cap π
π LIBRARY π
import it from whichever flavour of Scheme you're on, queen:
(import (rnrs)) ;R6RS
(import (rnrs bytevectors)) ;R6RS
(import (scheme base)) ;R7RS
β¨ SYNOPSIS β¨
two whole vibes, one name. pick your fighter:
(bytevector-copy! source source-start target target-start k) ;R6RS
(bytevector-copy! to at from start end) ;R7RS
π¦ DESCRIPTION π¦
R6RS β copies the bytes from source at indices source-start, β¦, source-start + k β 1 to consecutive indices in target starting at target-index. literally just sliding bytes over, periodt π«
R7RS β copies the bytes of bytevector from between start and end to bytevector to, starting at at. same energy, different arg list, iykyk π
π«Ά RETURN VALUES π«Ά
Returns unspecified values. like, don't expect a gift back, it's giving "the journey is the reward" π
π EXAMPLES π
R6RS β watch it work:
;; 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 β same slay, different signature:
;; 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)
π APPLICATION USAGE π
this procedure is common in (de)serialization and processing of binary data π₯ ngl tho, sometimes keeping track of all those indices gets mad cumbersome, and bytevector ports are lowkey more suitable in those situations π
π COMPATIBILITY π
okay this is the important tea β β R6RS and R7RS specify very different arguments for these procedures. and note in particular that it's not just a different argument order, the last argument is also different. so don't be out here mixing them up, bestie, that's a whole different function in your head π
π§ ERRORS π§
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. red flag behaviour, honestly π©
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. yes, catastrophically, dramatic much π
β SEE ALSO β
bytevector-copy(3scm)β the non-destructive sibling, go say hi π«Ά
π STANDARDS π
R6RS, R7RS. both certified iconic π
π HISTORY π
the arguments used by R7RS are consistent with SRFI-43 whereas R6RS is consistent with SRFI-66. ancient lore, fr fr π
π AUTHORS π
this page is part of the scheme-manpages project. it includes materials from the RnRS documents. more information can be found at https://github.com/schemedoc/manpages/. shoutout to the maintainers, main character energy fr π
π₯ BUGS π₯
implementations need to be careful to handle the case where the source and target bytevector ranges overlap in memory. that's the one place this gets spicy πΆοΈ overlap = chaos if you're not paying attention, so bestie please be careful π
ok that's the whole page!! no notes, 10/10, ate and left no crumbs πβ¨
sign-off time π this lil rewrite is from the 2021-02-20 edition of the Scheme Programmer's Manual β bytevector-copy!(3scm), mwah, see you in the group chat π
π¦
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2021 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms