close-port - close a port

LIBRARY

(import (rnrs))                     ;R6RS
(import (rnrs io ports))            ;R6RS
(import (scheme base))              ;R7RS

SYNOPSIS

(close-port port)

DESCRIPTION

Closes the port, rendering the port incapable of delivering or accepting data. If port is an output port, it is flushed before being closed. This has no effect if the port has already been closed. A closed port is still a port.
R6RS
If port is a custom port then the closer procedure is called before the port is really closed.

RETURN VALUES

Returns unspecified values.

EXAMPLES

(define p (open-output-file "hello.txt"))
(display "Hello, world\n" p)
(close-port p)

APPLICATION USAGE

Ports are often connected to some limited resource, such as a file descriptor. Closing ports is important to avoid resource leaks. Some implementations will garbage collect ports, but this is not required.

COMPATIBILITY

This procedure is new in R6RS and R7RS.

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.
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

close-input-port(3scm), call-with-port(3scm)

STANDARDS

R6RS, 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://github.com/schemedoc/manpages/.

BUGS

It is often better to use call-with-port(3scm) or one of the related procedures. They make it easier to ensure that a port is closed when an exception is raised.


Markup created by unroff 1.0sc,    March 04, 2023.