Default input and output streams
Factor handbook » Input and output » Streams

Prev:Stream protocol
Next:Stream utilities


Motivation for default streams

The default input stream is stored in a dynamically-scoped variable:
input-stream


Unless rebound in a child namespace, this variable will be set to a console stream for reading input from the user.

Words reading from the default input stream:
read1 ( -- elt )

read ( n -- seq )

read-into ( buf -- buf-slice more? )

read-until ( seps -- seq sep/f )

read-partial ( n -- seq )

read-partial-into ( buf -- buf-slice more? )

readln ( -- str/f )


If the default input stream is a character stream (stream-element-type outputs +character+), lines of text can be read:
readln ( -- str/f )


Seeking on the default input stream:
seek-input ( n seek-type -- )


A pair of combinators for rebinding the input-stream variable:
with-input-stream ( stream quot -- )

with-input-stream* ( stream quot -- )


The default output stream is stored in a dynamically-scoped variable:
output-stream


Unless rebound in a child namespace, this variable will be set to a console stream for showing output to the user.

Words writing to the default output stream:
flush ( -- )

write1 ( elt -- )

write ( seq -- )


If the default output stream is a character stream (stream-element-type outputs +character+), lines of text can be written:
print ( str -- )

nl ( -- )

bl ( -- )


Seeking on the default output stream:
seek-output ( n seek-type -- )


A pair of combinators for rebinding the output-stream variable:
with-output-stream ( stream quot -- )

with-output-stream* ( stream quot -- )


A pair of combinators for rebinding both default streams at once:
with-streams ( input output quot -- )

with-streams* ( input output quot -- )