call-with-port - call a procedure with a port, closing it afterwards
(import (rnrs)) ;R6RS
(import (rnrs io ports)) ;R6RS
(import (scheme base)) ;R7RS
(call-with-port port proc)
as an argument. If
is closed automatically and the values returned
does not return,
is not closed automatically, except perhaps when it is possible to
will never again be used for an input or output operation.
Returns whatever values
(call-with-port (open-input-file "config.scm") read)
There are also examples in the
This procedure is a convenience that sometimes makes it easier to
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
This procedure is identical in R6RS and R7RS, apart from the
differences in error handling.
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
does not accept one argument.
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.
This procedure is new in R6RS and later also became new in R7RS.
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Markup created by unroff 1.0sc, March 04, 2023.