make-bytevector(3scm)
π make-bytevector(3scm) π
okay so bestie, this is the Scheme Programmer's Manual page for make-bytevector β the little bytevector-maker that's lowkey carrying a lot of Scheme code. No cap, it's giving "fresh bytes, but make it cute." π
β¨ NAME β¨
make-bytevector β create a new bytevector
π LIBRARY π
import it from whichever RnRS situation you're in, bestie:
(import (rnrs)) ;R6RS
(import (rnrs bytevectors)) ;R6RS
(import (scheme base)) ;R7RS
π«Ά SYNOPSIS π«Ά
(make-bytevector k)
(make-bytevector k fill)
π DESCRIPTION π
Return a newly allocated bytevector of k bytes. Periodt. β¨
If the fill argument is missing, the initial contents of the returned bytevector are unspecified. Yes, bestie β unspecified means don't go assuming it's zeroed unless your implementation says so down below. π
If the fill argument is present, it must be an exact integer object. Every byte in the returned bytevector will be set to this value. Like, every single one. π
- R6RS β The
fillargument must be in the range[β128, 255]. Iffillis positive, it is interpreted as if passed tobytevector-u8-set!(3scm). If it is negative, it is instead used as if passed tobytevector-s8-set!(3scm). - R7RS β The
fillargument must be in the range[0, 255].
π§ IMPLEMENTATION NOTES π§
Not every Scheme is the same, and this is where the vibes get specific:
- Chez Scheme, Loko Scheme, (others?) β If
kis zero then the empty bytevector object is returned. - GNU Guile, Loko Scheme, (others?) β If
fillis missing then the bytevector is initialized to zeros. Slay for predictability. β¨ - Chibi Scheme β Even though Chibi is an R7RS implementation, the
fillargument is interpreted as in R6RS. This is a valid extension of R7RS.
π RETURN VALUES π
Returns a single object which is a bytevector object of the given length. If k is non-zero then the bytevector is fresh. If k is zero then the unique empty bytevector object may be returned.
So yeah β non-zero k means a new one; zero k means you might get the iconic shared empty bytevector. π
πΈ EXAMPLES πΈ
(make-bytevector 2 12)
=> #u8(12 12) ;R7RS notation
π₯ APPLICATION USAGE π₯
This procedure is used in code that works with mutable bytevectors. For some code an alternative is to use open-bytevector-output-port(3scm) and to build the data sequentially.
Both are valid, bestie β it's giving "choose your fighter." π¦
π COMPATIBILITY π
Portable code should provide the second argument, and should keep it in the range [0, 255].
That's the safe zone for maximum portability. Don't be out here raw-dogging make-bytevector with no fill and then acting surprised. π
π ERRORS π
This procedure can raise exceptions with the following condition types:
&assertion(R6RS) β The wrong number of arguments was passed or an argument was outside its domain.&implementation-restriction(R6RS) β There is not enough free memory to hold the new bytevector.- 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.
"fail catastrophically" is right there in the spec, bestie. Not me adding drama β that's literally the wording. π
π SEE ALSO π
Go check out u8-list->bytevector(3scm) β sibling behavior, different vibe. π
β STANDARDS β
R6RS, 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/.
π BUGS π
It is often a mistake to call this procedure without the fill argument. Unusual values of k can stress the Scheme implementation's memory allocator and cause a crash.
So likeβ¦ maybe don't be chaotic with k, and maybe do provide fill. Your allocator will thank you. π
later bestie β this was the Scheme Programmer's Manual, dated 2022-03-21, for make-bytevector(3scm). bye and slay π
β¨π«Ά
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2022 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms