bytevector-append(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

✨ bytevector-append ✨

ok bestie so you know how you have a bunch of bytevectors and you're like "ugh I wish these were ONE bytevector"?? yeah. that's this. this is the glow-up merge. πŸ’–

It lives in the Scheme Programmer's Manual (yes, the 3scm one, we stay iconic) β€” come thru 🫢


🌸 LIBRARY 🌸

(import (scheme base))              ;R7RS

that's it. that's the import. R7RS girlies rise πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

(bytevector-append bytevector ...)

note the ... β€” she takes any number of them. zero bytevectors? sure. forty? also fine. we don't gatekeep πŸ”₯


πŸ’œ DESCRIPTION πŸ’œ

Returns a newly allocated bytevector whose elements are the concatenation of the elements in the given bytevectors.

like, brand new. fresh out the box. not reusing anybody's memory, not mutating your originals β€” she's her own girl. you hand her a lineup of bytevectors, she lines all their bytes up in order and hands you back one single shiny bytevector. it's giving assembly line, it's giving "the way that she just concatenates" 😭✨


⭐ RETURN VALUES ⭐

Returns a single bytevector object.

one (1) bytevector. that's the whole vibe check. πŸ‘‘


πŸ¦‹ EXAMPLES πŸ¦‹

(bytevector-append #u8(0 1 2) #u8(3 4 5))
          => #u8(0 1 2 3 4 5)

see how 0 1 2 and 3 4 5 just… became 0 1 2 3 4 5?? no cap, that's the whole procedure and she ate. πŸ“


🌈 COMPATIBILITY 🌈

ok so important heads up: this procedure is absent from R6RS. 😭 your R6RS bestie does not have her. tragic, I know.

but don't spiral β€” one possible implementation is shown below:

(define (bytevector-append . bvs)
  (call-with-bytevector-output-port
    (lambda (p)
      (for-each (lambda (bv) (put-bytevector p bv)) bvs))))

you just open a bytevector output port, walk through every bv with for-each, put-bytevector each one in, and boom β€” she collected everything for you. DIY queen behavior honestly πŸ’…


πŸ’€ ERRORS πŸ’€

It is an error if one of the arguments is not a bytevector.

like if you pass her a string or a list or your hopes and dreams?? not a bytevector, not her problem, and honestly she may fail catastrophically. 😭 Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

read that again: or fail catastrophically. no graceful exit, no little apology note. just vibes ending. so maybe double-check your types first fr fr πŸ™ˆ


🧚 SEE ALSO 🧚


πŸ‘‘ STANDARDS πŸ‘‘

R7RS


πŸ’œ 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/.

like, respect the archivists, they're doing the lord's work 🫢


and that's the page bestie!! mwah πŸ’‹

with love from the Scheme Programmer's Manual, dated 2021-02-28, signed off on bytevector-append(3scm) β€” go forth and concatenate responsibly πŸŽ€βœ¨

πŸ“¦ where this page comes from