在 SLIME 中运行它并想知道为什么它在输出 format
之前等待 read
输入。
(defun wage ()
(format t "~&Enter wage: ")
(let ((wage (read)))
(format t "~&Enter hours: ")
(let ((hours (read)))
(format t "~&Earned ~S dollars." (* wage hours)))))
* (wage)
2
Enter wage:
3
Enter hours:
Earned 6 dollars.
NIL
最佳答案
发生这种情况是因为标准输出流是缓冲的,这意味着打印到它的东西实际上不会立即写入显示器。您需要在每个实例中的 (read)
之前调用 (finish-output)
以确保首先写入缓冲的任何内容。
关于lisp - READ 在 FORMAT 之前运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20157679/