Common Lisp 中的 format 何时真正打印?
我有以下 Common Lisp 代码:
(defun micro-read-eval-print ()
(format t "Micro > ")
(let ((form (read-line)))))
当我运行它时,我得到以下信息:
CL-USER> (micro-read-eval-print)
(m-quote a)
Micro > NIL
请注意,我输入了“(m-quote a)”,而 Lisp 解释器输出“Micro > NIL”。
现在,我预计这些事件会以相反的顺序发生。我本来希望“Micro >”首先被打印,因为格式声明首先出现。为什么不先打印出来?我该怎么做才能确保它首先被打印出来?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加
我相信您遇到了标准 io (stdio) 的缓冲,在 C 语言中,通常通过该语言中的 fflush() 绕过该缓冲。
finish-output
似乎是 Common Lisp 中 C 标准库的fflush
的等价物。Try adding
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
.