call-wit...put-port(3scm)
π NAME π
okay bestie, welcome to the call-wit...put-port(3scm) page from the Scheme Programmer's Manual β we're talking about call-with-string-output-port, and it's lowkey a whole vibe. π
call-with-string-output-portβ call a procedure with a string output port. that's the whole assignment. no cap.
π LIBRARY π
(import (rnrs)) ;R6RS
(import (rnrs io ports)) ;R6RS
β¨ SYNOPSIS β¨
(call-with-string-output-port proc)
π¦ DESCRIPTION π¦
okay so this procedure literally creates a textual output port that accumulates the characters written to it, then calls proc with that output port as an argument. Whenever proc returns, a string consisting of all of the port's accumulated characters is returned β and yes, that is regardless of the port's current position, bestie, no cap β and the port is closed. slay. β¨
heads up: the port should support theport-position(3scm)andset-port-position!(3scm)operations. like, those need to be part of its whole thing.
π§ IMPLEMENTATION NOTES π§
The port may or may not have an associated transcoder; if it does, the transcoder is implementation-dependent. so that part is not on us, iykyk.
π RETURN VALUES π
Returns a single value; a string. one value. a string. that's it. we're obsessed. π
πΈ EXAMPLES πΈ
here's the example, bestie β exact vibes:
(call-with-string-output-port
(lambda (p)
(for-each (lambda (x)
(display x p))
'("Hello " world #\newline))))
=> "Hello world\n"
π APPLICATION USAGE π
This procedure is commonly used when creating strings piecemeal. translation: when you're building a string bit by bit, this is the move. periodt.
π COMPATIBILITY π
This procedure is unique to R6RS. It is a wrapper around open-string-output-port(3scm). it's giving wrapper energy, honestly. π«Ά
π 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,procmust be a procedure that accepts one argument. so like, give it the right shape, bestie.
π SEE ALSO π
call-with-string-output-port(3scm)open-string-output-port(3scm)open-string-input-port(3scm)
β STANDARDS β
R6RS. that's the standard, bestie. β
π°οΈ HISTORY π°οΈ
This procedure is new to the reworked I/O in R6RS. iconic behavior, honestly β main character energy. π
π 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/.
xoxo, your Unix bestie π β footer vibes: source/version: Scheme Programmer's Manual; date: 2023-02-15; footer name: call-wit...put-port(3scm). mwah. π
π¦ 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