sbcl - 为什么不按顺序执行代码

sbcl - why not execute code in sequence

我正在从书中删除示例:ANSI Common Lisp,第 14.6 章条件。

sbcl 未按正确顺序打印提示:

示例代码:

(defun user-input (prompt)
    (format t prompt)
    (let ((str (read-line)))
      (or (ignore-errors (read-from-string str))
      nil)))

在sbcl测试中,提示不会按顺序打印:

* (defun user-input (prompt)
    (format t prompt)
    (let ((str (read-line)))
      (or (ignore-errors (read-from-string str))
      nil)))

STYLE-WARNING: redefining COMMON-LISP-USER::USER-INPUT in DEFUN

USER-INPUT
* (user-input "Please type an expression> ")
test
Please type an expression> 
TEST
* (user-input "Please type an expression> ")
#%@#+!!
Please type an expression> 
NIL
* 

但在 clisp 中,提示是按顺序打印的,并且按预期工作:

[5]> (defun user-input (prompt)
    (format t prompt)
    (let ((str (read-line)))
      (or (ignore-errors (read-from-string str))
You are in the top-level Read-Eval-Print loop.
Help (abbreviated :h) = this list
Use the usual editing capabilities.
(quit) or (exit) leaves CLISP.
  nil)))
USER-INPUT
[6]> (user-input "Please type an expression> ")
Please type an expression> #%@#+!!
NIL
[7]> 

在后面插入 force-output format 在您的 user-input 中以避免 i/o 缓冲问题: 通常,在换行符或 force-outputfinish-output.