Common Lisp格式实际上什么时候打印? [英] When does format actually print in Common Lisp?
问题描述
(defun micro-read-eval-print()
(格式tMicro>)
(let((form(read-line))))
当我运行它时,我得到以下内容:
CL-USER> (micro-read-eval-print)
看起来就是C标准库的Common Lisp相当于
(m-quote a)
Micro>请注意,我输入(m-quote a),而Lisp解释器输出$ m $ a $ Micro> NIL。
现在,我预计这些事件会以相反的顺序发生。自从格式化语句首先打印出来之后,我预料会先打印出Micro>。为什么不先打印?我该怎么做,以确保它是首先打印?解决方案尝试添加
(defun micro-read-eval-print()
(format tMicro>)
(finish-output)
(let((form(read-line)))))
我相信你遇到标准io(stdio)的缓冲,在C语言中,这个语言通常被
fflush()
绕过。
finish-output fflush
。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?
解决方案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'sfflush
.这篇关于Common Lisp格式实际上什么时候打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!