Scheme Programmer's Manual

NAME

close-input-port, close-output-port - close a port

LIBRARY

(import (rnrs))                     ;R6RS
(import (rnrs io simple))           ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS

SYNOPSIS

(close-input-port port)
(close-output-port port)

DESCRIPTION

Closes the file associated with port, rendering the port incapable of delivering or accepting characters. These routines have no effect if the file has already been closed.
R6RS
If port is a custom port then the closer procedure is called before the port is really closed.
Custom ports have a single closer procedure, so they do not compose well with only closing one direction. R6RS does not explicitly make any mention of closing only one direction.
R7RS
Scheme implementations may provide ports which are simultaneously input and output ports, such as sockets; the close-input-port and close-output-port procedures can then be used to close the input and output sides of the port independently.

RETURN VALUES

Returns unspecified values.

EXAMPLES

(define p (open-output-file "hello.txt")) (display "Hello, world\n" p) (close-output-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.

RATIONALE

In R6RS these procedures are part of the "simple I/O" library, which is provided for compatibility with code written for R5RS and earlier reports.

COMPATIBILITY

These procedures are provided for portability with code written for R5RS and earlier reports.

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.
It is an error to apply these procedures to a port which is not an input or output port, respectively.

SEE ALSO

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

STANDARDS

R4RS, IEEE Scheme, R5RS, 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

BUGS

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

Index

NAME
LIBRARY
SYNOPSIS
DESCRIPTION
RETURN VALUES
EXAMPLES
APPLICATION USAGE
RATIONALE
COMPATIBILITY
ERRORS
SEE ALSO
STANDARDS
AUTHORS
BUGS
Return to Main Contents