bytevector-fill!(3scm)

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

πŸ’– bytevector-fill!(3scm) πŸ’–

okay so bestie, welcome to the Scheme Programmer's Manual β€” yes that's the actual manual name, she's fancy, we love her β€” and today's main character is bytevector-fill!. Buckle up πŸŽ€


✨ NAME ✨

bytevector-fill! β€” fill a bytevector with a value. that's it. that's the whole gig. and she ate πŸ’…


πŸ“š LIBRARY πŸ“š

import her like this, depending on your era:

(import (rnrs))                     ;R6RS
(import (rnrs bytevectors))         ;R6RS

πŸ¦‹ SYNOPSIS πŸ¦‹

(bytevector-fill! bytevector fill)

🌸 DESCRIPTION 🌸

so what she does is: this procedure stores fill in every single element of bytevector. every one. no cap. πŸ’―

the fill value has to be an exact integer living in the interval [-128, 255]. and the negative fill values? they get interpreted as bytes, viz.:

(bytevector-fill! bytevector (bitwise-and fill #xff))

🫢 RETURN VALUES 🫢

returns unspecified values. she gives you nothing back, she's mysterious like that πŸ™ˆ


⭐ EXAMPLES ⭐

(let ((a (u8-list->bytevector '(1 2 3))))
  (bytevector-fill! a 0)
  a)
   => #vu8(0 0 0)

see how she just zeroed the whole thing out? iconic πŸŽ€


πŸ‘‘ APPLICATION USAGE πŸ‘‘

ok so this one's kinda the "responsible bestie" move: this procedure is sometimes useful to clear sensitive parts of memory, like bytevectors holding cryptographic keys. πŸ”

but bestie listen β€” this is optimistic but is not in any way guaranteed to wipe the data from memory. 😭 so like, don't @ me if your keys are still lurking, fr fr.

also, heads up: a bytevector that contains the specified value would normally be created from scratch with make-bytevector(3scm).


🌈 COMPATIBILITY 🌈

the only difference in behavior between implementations should be in how fast it runs. that's it. that's the drama. and just so you know β€” this procedure is not present in R7RS-small. 🫠


πŸ’€ ERRORS πŸ’€

she can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” the wrong number of arguments was passed or an argument was outside its domain. basically: you fumbled the input, bestie πŸ€·β€β™€οΈ

πŸ”₯ SEE ALSO πŸ”₯


πŸ’œ STANDARDS πŸ’œ

R6RS ⭐


🧚 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/.


and that's the whole vibe check, bestie πŸ’– mwah, go fill those bytevectors responsibly β€” this page is from 2021-02-23 and it's bytevector-fill!(3scm) all day, every day πŸ“βœ¨

πŸ“¦ where this page comes from