port?(3scm) Scheme Programmer's Manual port?(3scm)

port?, input-port?, output-port? - test for ports and their direction

(import (rnrs))                     ;R6RS
(import (rnrs io ports))            ;R6RS
(import (rnrs io simple))           ;R6RS, except port?
(import (scheme base))              ;R7RS
(import (scheme r5rs))              ;R7RS, except port?

(port? obj)
(input-port? obj)
(output-port? obj)

The port? procedure returns #t if the argument is a port, and #f otherwise.

The input-port? procedure returns #t if the argument is an input port (or a combined input and output port), and #f otherwise.

The output-port? procedure returns #t if the argument is an output port (or a combined input and output port), and #f otherwise.

Returns a single boolean object.

(port? (current-output-port))         => #t
(port? 'not-a-port)                   => #f
(input-port? (current-input-port))    => #t
(output-port? (current-output-port))  => #t
(input-port? (current-output-port))   => #f

The port? procedure is new in R6RS and new in R7RS. The input-port? and output-port? procedures also accept combined input/output ports.

This procedure can raise exceptions with the following condition types:
&assertion (R6RS)
The wrong number of arguments was passed.
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.

textual-port?(3scm), input-port-open?(3scm), current-input-port(3scm)

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

The input-port? and output-port? procedures first appeared in R2RS.

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

2026-07-22