Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does format actually print in Common Lisp?

I have the following Common Lisp code:

(defun micro-read-eval-print ()
    (format t "Micro > ")
    (let ((form (read-line)))))

When I run it, I get the following:

CL-USER> (micro-read-eval-print)
(m-quote a)
Micro > NIL

Note that I typed in "(m-quote a)", while the Lisp interpreter output "Micro > NIL".

Now, I would have expected these events to happen in the reverse order. I would have expected "Micro > " to have been printed first since the format statement comes first. Why isn't it printed first? And what do I have to do to make sure it is printed first?

like image 911
Paul Reiners Avatar asked Aug 06 '10 17:08

Paul Reiners


1 Answers

Try adding

(defun micro-read-eval-print ()
    (format t "Micro > ")
    (finish-output)
    (let ((form (read-line)))))

I believe you are encountering the buffering of standard io (stdio) which, in C, is commonly bypassed via fflush() in that language.

finish-output appears to be the Common Lisp equivalent of C standard library's fflush.

like image 63
Heath Hunnicutt Avatar answered Sep 29 '22 02:09

Heath Hunnicutt