call-wit...put-port(3scm)

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

πŸ’– NAME πŸ’–

okay so bestie, welcome to call-with-bytevector-output-port β€” the procedure that literally calls your procedure with a bytevector output port. that's the whole vibe. 🫢

this page lives in the Scheme Programmer's Manual, and ngl it's a good one.


🌸 LIBRARY 🌸

(import (rnrs))                     ;R6RS
(import (rnrs io ports))            ;R6RS

both of these, bestie. that's where the magic lives. ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

(call-with-bytevector-output-port proc)
(call-with-bytevector-output-port proc maybe-transcoder)

two flavors, same energy πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

okay so here's the tea. this procedure creates an output port that just sits there accumulating all the bytes you write to it. then it calls proc with that output port as its argument. main character port behavior, honestly.

whenever proc returns, you get back a bytevector made of all of the port's accumulated bytes β€” and listen, that's "regardless of the port's current position", so the position does not matter even a little bit. then the port gets closed. periodt.

the transcoder that's associated with the output port? it gets determined exactly the same way as for a call to open-bytevector-output-port(3scm). iykyk. 🌈


⭐ RETURN VALUES ⭐

returns a single value β€” a bytevector. one (1) bytevector, no cap. πŸ’œ


πŸ”₯ EXAMPLES πŸ”₯

okay these are iconic, look:

(call-with-bytevector-output-port
  (lambda (p)
    (put-u8 p 7)))
        => #vu8(7)

ate. πŸ’… and here's the one with a transcoder:

(call-with-bytevector-output-port
  (lambda (p)
    (put-string p "0123"))
  (native-transcoder))
        => #vu8(48 49 50 51)

look at those bytes. 48 49 50 51. slayed. πŸ“


🧚 APPLICATION USAGE 🧚

this procedure is commonly used when you're creating bytevectors piecemeal. like, bit by bit, one little write at a time. it's giving arts and crafts. 🎨


πŸ’€ COMPATIBILITY πŸ’€

so this one is unique to R6RS β€” nobody else has it. it's lowkey just a wrapper around open-bytevector-output-port(3scm). that's the whole thing. πŸ™ˆ


⚠️ ERRORS ⚠️

heads up bestie, 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: proc has to be a procedure that can accept one argument, and maybe-transcoder has to be a transcoder or #f. don't try to be cute with it. 😭

πŸ‘‘ SEE ALSO πŸ‘‘

  • open-bytevector-output-port(3scm)
  • open-bytevector-input-port(3scm)

go read those too, bestie, they're family. 🫢


🌟 STANDARDS 🌟

R6RS


πŸ’« HISTORY πŸ’«

this procedure is new to the reworked I/O in R6RS. fresh out the box. ✨


πŸ’– 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/. πŸŽ€


and that's the whole page! this lil gem is from the scheme-manpages project (call-wit...put-port(3scm)), dated 2023-02-15. mwah, go write some bytes πŸ’‹πŸŒΈ

πŸ“¦ where this page comes from