make-broadcast-stream
make-broadcast-stream Function
Syntax:
make-broadcast-stream &rest streams → broadcast-stream
Arguments and Values:
stream—an output stream.
broadcast-stream—a broadcast stream.
Description:
Returns a broadcast stream.
Examples:
(setq a-stream (make-string-output-stream)
b-stream (make-string-output-stream)) → #<String Output Stream>
(format (make-broadcast-stream a-stream b-stream)
"this will go to both streams") → NIL
(get-output-stream-string a-stream) → "this will go to both streams"
(get-output-stream-string b-stream) → "this will go to both streams"
Exceptional Situations:
Should signal an error of type type-error if any stream is not an output stream.
See Also:
broadcast-stream-streamsExpanded Reference: make-broadcast-stream
Basic Usage
make-broadcast-stream creates an output stream that sends output to all of its component streams simultaneously.
(let ((a (make-string-output-stream))
(b (make-string-output-stream)))
(let ((broadcast (make-broadcast-stream a b)))
(write-string "hello to both" broadcast))
(list (get-output-stream-string a)
(get-output-stream-string b)))
=> ("hello to both" "hello to both")
Using with format
(let ((s1 (make-string-output-stream))
(s2 (make-string-output-stream)))
(format (make-broadcast-stream s1 s2)
"this will go to both streams")
(list (get-output-stream-string s1)
(get-output-stream-string s2)))
=> ("this will go to both streams" "this will go to both streams")
Discarding Output (No Component Streams)
A broadcast stream with no components is a "bit bucket" -- all output is discarded.
(let ((s (make-broadcast-stream)))
(write-string "discarded" s)
(format s "also discarded ~D" 42)
(output-stream-p s))
=> T
Three or More Streams
Any number of output streams can be combined.
(let ((streams (loop repeat 3 collect (make-string-output-stream))))
(let ((bc (apply #'make-broadcast-stream streams)))
(write-string "triple" bc))
(mapcar #'get-output-stream-string streams))
=> ("triple" "triple" "triple")