u8-list->bytevector(3scm)

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

πŸ’… 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 πŸ‘‘


🌟 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