u8-list->bytevector(3scm)
π
u8-list->bytevector(3scm) β Scheme Programmer's Manual π
okay so welcome to the Scheme Programmer's Manual, section 3scm, bestie! This is the group chat for u8-list->bytevector, sint-list->bytevector, and uint-list->bytevector. π«Ά
πΈ NAME πΈ
Bestie, listen: u8-list->bytevector, sint-list->bytevector, and uint-list->bytevector are the little conversion crew that turns a list of integers into a bytevector. Iconic behavior, honestly. β¨
π LIBRARY π
(import (rnrs)) ;R6RS
(import (rnrs bytevectors)) ;R6RS
π¦ SYNOPSIS π¦
(u8-list->bytevector list)
(sint-list->bytevector list endianness size)
(uint-list->bytevector list endianness size)
π DESCRIPTION π
So here's the vibe: these procedures convert a list of exact integers to a bytevector according to size and endianness. The integers are encoded in the same order as they appear in list. No cap. π§
The sint-list->bytevector procedure uses the two's complement representation, and uint-list->bytevector is for unsigned integers. Slay. π
The u8-list->bytevector procedure is the same as bytevector->uint-list with a size of 1. yes bestie, that is literally what the page says π
β RETURN VALUES β
Returns a newly allocated bytevector. New, fresh, glowing. β¨
π EXAMPLES π
Not me putting the whole serve in a code block: π
(u8-list->bytevector '(1 2 3))
=> #vu8(1 2 3)
(uint-list->bytevector '(#xAA55 #x55AA #x4200) (endianness big) 2)
=> #vu8(#xAA #x55 #x55 #xAA #x42 #x0)
(sint-list->bytevector '(-2 -1 0 1 2) (endianness little) 1)
=> #vu8(254 255 0 1 2)
(let ((b (u8-list->bytevector '(1 2 3 255 1 2 1 2))))
(bytevector->sint-list b (endianness little) 2))
=> (513 -253 513 513)
(let ((b (u8-list->bytevector '(1 2 3 255 1 2 1 2))))
(bytevector->uint-list b (endianness little) 2))
=> (513 65283 513 513)
π COMPATIBILITY π
Tiny compatibility tea: the u8-list->bytevector procedure is absent from R7RS-small. You can use the bytevector(3scm) procedure instead, but it uses a variable argument list, which is usually less efficient. The other procedures have no equivalent in R7RS-small. iykyk π
β οΈ Also: if the returned bytevector would be empty then the returned bytevector does not have to be newly allocated. Important little caveat, bestie.
π 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.
π SEE ALSO π
make-bytevector(3scm)bytevector->u8-list(3scm)bytevector(3scm)endianness(7scm)
π STANDARDS π
R6RS. Periodt. π
π¦ HISTORY π¦
These procedures are new for R6RS, where they were based on SRFI-74. We love a documented origin story. β¨
π«Ά 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/.
Source/version check: this cutie is from the Scheme Programmer's Manual, page u8-list->bytevector(3scm), dated 2021-03-06. Bye bestie! ππ¦π
π¦ 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