bytevector-u8-set!(3scm)
π bytevector-u8-set!(3scm) π
Okay bestie, so we're looking at bytevector-u8-set!(3scm) from the Scheme Programmer's Manual, and it's literally the glow-up your bytevectors have been waiting for. This is the "modify a byte in a bytevector" era and we are obsessed. β¨
π LIBRARY π
So first things first, you gotta import this vibe from the right place. Like, pick your era:
(import (rnrs)) ;R6RS
(import (rnrs bytevectors)) ;R6RS
(import (scheme base)) ;R7RS
No cap, these are the three possible places to get this procedure from. Slay.
π¦ SYNOPSIS π¦
Okay so the way you call this iconic procedure is:
(bytevector-u8-set! bytevector k octet)
(bytevector-s8-set! bytevector k byte) ;R6RS
That's it. That's the whole mood. π
πΈ DESCRIPTION πΈ
So here's the tea, bestie: bytevector-u8-set! is gonna take your octet and store it at index k of your bytevector. It's giving "main character energy" because it's literally changing the bytevector in place. Periodt. π₯
And bytevector-s8-set!? That one stores the two's complement representation of byte. Not me explaining two's complement in a manpage, but here we are and it ate. π
β RETURN VALUES β
Returns unspecified values. Yep, that's it. It doesn't return anything useful, it just does the thing and dips. Lowkey iconic behavior. π
π EXAMPLES π
Okay so here's a real example that's literally gonna make you understand everything:
(let ((b (make-bytevector 16 -127)))
(bytevector-s8-set! b 0 -126)
(bytevector-u8-set! b 1 246)
(list
(bytevector-s8-ref b 0)
(bytevector-u8-ref b 0)
(bytevector-s8-ref b 1)
(bytevector-u8-ref b 1)))
=> (-126 130 -10 246)
Look at that output bestie: (-126 130 -10 246). It's giving "the math is mathing" and we love that for us. π«Ά
π COMPATIBILITY π
Okay so here's the thing: bytevector-s8-set! is literally absent from R7RS. Like, it just didn't make the cut. But don't worry bestie, because there's a possible implementation shown below and it's giving "I made it work":
(define (bytevector-s8-set! bytevector k byte)
(let ((octet (if (< byte 0) (+ 256 byte) byte)))
(bytevector-u8-set! bytevector k octet)))
See what they did there? They converted the signed byte to an unsigned octet and then used the big sister bytevector-u8-set! to handle it. Highkey clever. π
π ERRORS π
This procedure can raise exceptions with the following condition types, and you need to know about them:
&assertion(R6RS) β The wrong number of arguments was passed or an argument was outside its domain. The indexkwas not a valid index forbytevector. Basically if you mess up the vibe check, this is what you get. So make sure yourkis actually valid, okay? π
π SEE ALSO π
bytevector-u16-set!(3scm)β because sometimes you need more than 8 bits and that's valid.
π§ STANDARDS π§
R6RS. That's the standard, bestie. It's the era this procedure was born in. π
π 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/. I know, I know, it's not a link you can click but it's still iconic. π
Alright bestie, that's the whole page. This manual page is from the Scheme Programmer's Manual and it's dated 2021-02-28. Stay slaying with those bytevectors and remember: no cap, you're now a bytevector-u8-set! expert. π
β¨
π¦ 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