首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么不按顺序执行代码?

为什么不按顺序执行代码?
EN

Stack Overflow用户
提问于 2015-08-10 03:18:03
回答 1查看 220关注 0票数 0

我从书中摘录了一个例子: ANSI Common,Charpter14.6条件。

sbcl不按正确顺序打印提示符:

示例代码:

代码语言:javascript
运行
复制
(defun user-input (prompt)
    (format t prompt)
    (let ((str (read-line)))
      (or (ignore-errors (read-from-string str))
      nil)))

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

代码语言:javascript
运行
复制
* (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中,提示按顺序打印,并按预期工作:

代码语言:javascript
运行
复制
[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]> 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-10 05:24:29

force-output后面插入format,以避免i/o缓冲问题:通常,只有换行符、force-outputfinish-output才会将任何内容打印到设备上。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31911167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档