Forcing buffered output

Many CL implementations (SBCL in particular) perform output in a buffered manner. Sometimes this may cause a confusion, because it may reverse the order of effects. Like in the following example it may be possible to enter something before seeing ‘?’.

(defun ask ()
(princ '?)

Also if you are writing an application, that should interact with some other program (for example over a pipe) and there are hard limits on the interaction speed, buffering can be a problem.

For such cases there’s a standard function finish-output, that initiates dumping any buffered output. There’s also force-output, that does the same thing, but asynchronously (i.e. doesn’t wait for the actual writing to finish).