bytevector-length(3scm)
π bytevector-length β the length of a bytevector π
okay so bestie, this one's from the Scheme Programmer's Manual (the 3scm corner of it) and honestly? it's giving "small but iconic." let's get into it π«Ά
β¨ LIBRARY β¨
like, import it from whichever flavour you're on:
(import (rnrs)) ;R6RS
(import (rnrs bytevectors)) ;R6RS
(import (scheme base)) ;R7RS
π SYNOPSIS π
(bytevector-length bytevector)
that's it. that's the whole vibe check. π
πΈ DESCRIPTION πΈ
so bytevector-length returns β as an exact integer object β the number of bytes in bytevector. and here's the tea: the length of a bytevector is fixed. it doesn't grow, it doesn't shrink, it is what it is. main character energy, no cap. β¨
π¦ IMPLEMENTATION NOTES π¦
ngl this is a fun little detail: all extant implementations use fixnums to represent bytevector lengths. but β plot twist β this is not required. so don't go building your whole personality on it, iykyk. π
β RETURN VALUES β
returns a single value, which is the length of the bytevector. one value. simple. slay. π
π₯ EXAMPLES π₯
(bytevector-length #vu8(1 2 3))
=> 3
three bytes in, three out. ate. π
π APPLICATION USAGE π
this procedure is often used in code that deals with variable-length binary data β like when you're parsing stuff and you literally need to know how much of it there is. very much a supporting-role-with-iconic-lines situation. π¬
π COMPATIBILITY π
works the same in all known Scheme implementations. periodt. π
it also pops up in other languages, e.g. as the len function on byte objects in Python. same energy, different font. π
π 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. rude but fair.- 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. no we're not being dramatic, that's the actual wording. π
π§ SEE ALSO π§
make-bytevector(3scm)β go make one, then come back and measure it π
π STANDARDS π
R6RS, R7RS β certified, twice. β
π HISTORY π
the name first appeared in R6RS. and SRFI-4 is the first SRFI to define a procedure similar to this one. so like, it has lore. πΈ
π 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/. π«Ά
lowkey obsessed with how a one-line procedure got a whole manpage. deserved though. π
alright bestie that's the whole thing β sourced from the scheme-manpages project, version dated 2020-12-31, page bytevector-length(3scm). go forth and count your bytes β¨π¦π
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2020 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms