call-wit...put-port(3scm)
π 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:prochas to be a procedure that can accept one argument, andmaybe-transcoderhas 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
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2023 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms