flush-output-port(3scm) Scheme Programmer's Manual flush-output-port(3scm)

flush-output-port - flush buffered data from a port to its sink

(import (rnrs))                     ;R6RS
(import (rnrs io ports))            ;R6RS
(import (scheme base))              ;R7RS

(flush-output-port)                 ;R7RS
(flush-output-port output-port)

Flushes any buffered output from the buffer of output-port to the underlying file, device, or object.

The standard output port is block buffered and it is not closed on exit. A manual flush is needed before exiting the program.

Returns unspecified values.
Returns an unspecified value.

(display "Enter your name: ")
(flush-output-port (current-output-port))
(define name (get-line (current-input-port)))

Used to manually flush a port's internal buffers. The port is automatically flushed when the port is closed, so there is no need for a manual flush before closing a port.

Output ports are line buffered, block buffered or unbuffered. Buffering is typically good for performance, but sometimes applications need to write data immediately.

In R7RS, if output-port is omitted, it defaults to the value returned by current-output-port(3scm).

This procedure can raise exceptions with the following condition types:

&assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain.
&i/o-encoding (R6RS)
The port's transcoder is in raise mode and it encountered a character that could not be translated into bytes. The untranslated character can be retrieved with i/o-encoding-error-char(3scm).
&i/o-write (R6RS)
There was an I/O error during the write operation.
&i/o-port (R6RS)
This condition specifies the port object related to the &i/o-write condition.
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.

call-with-port(3scm), close-port(3scm)

R6RS, R7RS

This procedure first appeared in R6RS as part of the reworked I/O system.

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

2023-07-24