put-u8(3scm)

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

πŸ’– NAME πŸ’–

Hey bestie, meet put-u8(3scm) β€” this page is all about put-u8 and write-u8, the little cuties that write a byte to a binary output port. Manual name: put-u8(3scm). Periodt. πŸ’…


🌈 LIBRARY 🌈

Grab the right import for your vibe:

(import (rnrs))                     ;R6RS
(import (rnrs io ports))            ;R6RS
(import (scheme base))              ;R7RS

✨ SYNOPSIS ✨

(put-u8 binary-output-port byte)    ;R6RS
(write-u8 byte)                     ;R7RS
(write-u8 byte binary-output-port)  ;R7RS

πŸ¦‹ DESCRIPTION πŸ¦‹

It writes the byte to the given binary-output-port. That's the whole assignment, bestie β€” no cap. πŸ’–


πŸŽ€ IMPLEMENTATION NOTES πŸŽ€

Chibi Scheme

The current-output-port(3scm) at program start is both textual and binary. It should normally not be possible to use write-u8 on the current output port before rebinding it to a binary output port (which is not possible in R6RS). So yeah, lowkey a little situation there. 😭


🌸 RETURN VALUES 🌸

R6RS

Returns unspecified values. The vibe is β€œyou get something, but it's not the main character.” ✨

R7RS

Returns a unspecified value. Yes, exactly like that. πŸ’€


🧚 EXAMPLES 🧚

;; R7RS code to create a file with the single line "A"
(call-with-port (open-output-file "test.txt")
 (lambda (p)
   (write-u8 65 p)
   (write-u8 10 p)))

πŸ’œ APPLICATION USAGE πŸ’œ

Commonly used in applications that create binary files or other binary data. There is often a mix of single bytes intermixed with larger writes with put-bytevector(3scm). Basically, it's giving β€œtiny byte, big file energy.” 🫢


πŸ”₯ 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. In particular, byte must be an exact integer between 0 and 255. So bestie, keep it in range, fr fr. 😭
  • 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. Not β€œfail catastrophically” πŸ˜­πŸ’€ β€” that's the actual warning, so don't play with it.

πŸ‘‘ SEE ALSO πŸ‘‘


⭐ STANDARDS ⭐

R6RS, R7RS. Both flavors got a seat at the table. πŸ’…


🌻 HISTORY 🌻

The put-u8 procedure is new to the reworked I/O system introduced with R6RS. The write-u8 procedure is new in R7RS and is similar to write-char(3scm) but works with binary output ports, which did not exist in R5RS. Iconic glow-up behavior, honestly. ✨


πŸ“ 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/. 🫢


mwah πŸ’‹ β€” this cutie comes from the Scheme Programmer's Manual, dated 2022-04-07, under put-u8(3scm). byeee bestie! πŸŽ€βœ¨

πŸ“¦ where this page comes from