| call-with-port(3scm) | Scheme Programmer's Manual | call-with-port(3scm) |
NAME
call-with-port - call a procedure with a port, closing it afterwardsLIBRARY
(import (rnrs)) ;R6RS (import (rnrs io ports)) ;R6RS (import (scheme base)) ;R7RS
SYNOPSIS
(call-with-port port proc)
DESCRIPTION
Calls proc with port as an argument. If proc returns, port is closed automatically and the values returned by proc are returned.If proc does not return, port is not closed automatically, except perhaps when it is possible to prove that port will never again be used for an input or output operation.
RETURN VALUES
Returns whatever values proc returns.EXAMPLES
(call-with-port (open-input-file "config.scm") read)
There are also examples in the put-bytevector(3scm) and put-u8(3scm) pages.
APPLICATION USAGE
This procedure is a convenience that sometimes makes it easier to structure code.RATIONALE
Because Scheme's escape procedures have unlimited extent, it is possible to escape from the current continuation but later to resume it. If implementations were permitted to close the port on any escape from the current continuation, then it would be impossible to write portable code using both call-with-current-continuation(3scm) and call-with-port(3scm).COMPATIBILITY
This procedure is identical in R6RS and R7RS, apart from the differences in error handling.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, this is raised if procedure does not accept one argument.
- R7RS
- The assertions described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.
SEE ALSO
call-with-bytevector-output-port(3scm), call-with-string-output-port(3scm), call-with-input-file(3scm), with-input-from-file(3scm)STANDARDS
R6RS, R7RSHISTORY
This procedure is new in R6RS and later also became new in R7RS.AUTHORS
This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.| 2022-05-01 |