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

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

πŸ’– 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 the port-position(3scm) and set-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, proc must be a procedure that accepts one argument. so like, give it the right shape, bestie.

πŸ‘€ SEE ALSO πŸ‘€

⭐ 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