我正在阅读 Practical Common Lisp 这本书,并且得到了意想不到的行为。代码如下:
(defun prompt-read (prompt)
(format *standard-output* "~a: " prompt)
(force-output *standard-output*)
(read-line *standard-input*))
(defun prompt-for-cd ()
(make-cd
(prompt-read "Title")
(prompt-read "Artist")
(or (parse-integer (prompt-read "Rating") :junk-allowed t) 0)
(y-or-n-p "Ripped [y/n]: ")))
程序应该提示用户输入标题、接受标题、提示用户输入艺术家、接受艺术家等,直到用户输入所有信息。只需在 REPL 中运行提示读取即可成功提示用户输入所需的提示并返回结果。但是,这是我运行提示 for-cd 的输出:
我的程序仍然接受输入,但在第一次提示后停止提示用户。
编译并加载我定义函数的文件似乎显示了上次我运行prompt-for-cd 时应该向用户显示的提示。这是它的屏幕截图:
经过一番调查,我注意到这只发生在 Sly 的 REPL 中。这是我使用 SBCL 加载文件时程序的输出:
如何让控制台提示在 Sly 中按预期工作?
@anthony - 您的问题得到了可以接受的答案吗?
我在 macOS 13.4.1(c) 上运行 sbcl 2.2.9,使用 sly 版本 1.0.43,并且我没有遇到任何有关提示的问题。