call-with-string-output-port - call a procedure with a string output port
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs io ports)) ;R6RS
SYNOPSIS
(call-with-string-output-port proc)
DESCRIPTION
Creates a textual output port that accumulates the characters written
to it and calls
proc
with that output port as an argument.
Whenever
proc
returns, a string consisting of all of the port's accumulated
characters (regardless of the port's current position) is returned and
the port is closed.
The port should support the
port-position(3scm)
and
set-port-position!(3scm)
operations.
IMPLEMENTATION NOTES
The port may or may not have an associated transcoder; if it does, the
transcoder is implementation-dependent.
RETURN VALUES
Returns a single value; a string.
EXAMPLES
(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.
COMPATIBILITY
This procedure is unique to R6RS. It is a wrapper around
open-string-output-port(3scm).
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.
SEE ALSO
call-with-string-output-port(3scm),
open-string-output-port(3scm)
open-string-input-port(3scm)
STANDARDS
R6RS
HISTORY
This procedure is new to the reworked I/O in R6RS.
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/
.
Markup created by unroff 1.0sc, March 04, 2023.