Skip to main content

interactive-stream-p

interactive-stream-p Function

Syntax:

interactive-stream-p stream → generalized-boolean

Arguments and Values:

stream—a stream.

generalized-boolean—a generalized boolean.

Description:

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

Examples:

(when (> measured limit) 
(let ((error (round (\* (- measured limit) 100)
limit)))
(unless (if (interactive-stream-p \*query-io\*)
(yes-or-no-p "The frammis is out of tolerance by ~D%.~@
Is it safe to proceed? " error)
(< error 15)) ;15% is acceptable
(error "The frammis is out of tolerance by ~D%." error))))

Exceptional Situations:

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

See Also:

Section 21.1 (Stream Concepts)

Expanded Reference: interactive-stream-p

Basic Usage

interactive-stream-p returns true if the stream is interactive (e.g., a terminal), false otherwise.

;; String streams are not interactive
(interactive-stream-p (make-string-input-stream "test"))
=> NIL

String Output Stream

(interactive-stream-p (make-string-output-stream))
=> NIL

Conditional Behavior Based on Interactivity

A common use is to vary behavior depending on whether the user is present at a terminal.

;; Example pattern (not runnable as-is since it depends on the environment)
;; (if (interactive-stream-p *query-io*)
;; (yes-or-no-p "Proceed?")
;; t) ; auto-accept in non-interactive mode

Standard Streams

The result for *standard-input* or *terminal-io* depends on the implementation and the environment.

;; In a REPL session, these would typically return T:
;; (interactive-stream-p *standard-input*) -> T
;; In a batch/script environment, they might return NIL.