Skip to main content

open-stream-p

open-stream-p Function

Syntax:

open-stream-p stream → generalized-boolean

Arguments and Values:

stream—a stream.

generalized-boolean—a generalized boolean.

Description:

Returns true if stream is an open stream; otherwise, returns false.

Streams are open until they have been explicitly closed with close, or until they are implicitly closed due to exit from a with-output-to-string, with-open-file, with-input-from-string, or with-open-stream form.

Examples:

(open-stream-p \*standard-input\*) → true 

Affected By:

close.

Exceptional Situations:

Should signal an error of type type-error if stream is not a stream.

Expanded Reference: open-stream-p

Basic Usage

open-stream-p returns true if the stream is open, false if closed.

(open-stream-p *standard-input*)
=> T

Newly Created Streams Are Open

(let ((s (make-string-output-stream)))
(open-stream-p s))
=> T

After Closing

(let ((s (make-string-output-stream)))
(close s)
(open-stream-p s))
=> NIL

Streams Closed by with-open-stream

Streams are automatically closed on exit from with-open-stream.

(let (saved)
(with-open-stream (s (make-string-input-stream "test"))
(setq saved s)
(format nil "inside: ~A" (open-stream-p s)))
;; After exiting, saved stream is closed
(list (open-stream-p saved)))
=> (NIL)