【问题标题】:sbcl - why not execute code in sequence [duplicate]sbcl - 为什么不按顺序执行代码[重复]
【发布时间】:2015-11-01 20:56:00
【问题描述】:

我正在删除书中的示例: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]> 

【问题讨论】:

  • 输出在 SBCL 中缓冲。查看函数 force-output 和 finish-output。

标签: io common-lisp sbcl clisp


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 2011-10-10
    • 1970-01-01
    相关资源
    最近更新 更多