Vin*_*inn 1 executable sbcl common-lisp
我用 emacs + slime 开发 common lisp。我的机器是 mac pro M1。而且,我使用 kitty 终端模拟器。
当我在 repl 中运行我的应用程序(参见末尾的代码)时,它工作正常。
当我创建并运行可执行文件时,就好像程序的顺序不同了。
例如,我有 5 个问题需要用户输入......
(defpackage custom-sender
;; import the exactly the symbols I need from a package
(:import-from :cl-json :encode-json-to-string)
(:use :cl)
(:export :main))
(in-package custom-sender)
(defun main()
(asking-questions))
(defun asking-questions ()
(let ((firstname (prompt-read "What is the firstname of the contact?"))
(email (prompt-read "What is their email?"))
(job (prompt-read "What is the job?"))
(first-line (prompt-read "what is the first line of their address?"))
(sending-account (prompt-read "Which email account do you want to send from? (e2, e3 etc)")))
(status-update "some text ~a" email);; <-- this function is executed BEFORE the "sending-account" question is asked
... ) ;;<-- end of let block
)
Run Code Online (Sandbox Code Playgroud)
(defun status-update (message value)
(format *query-io* (concatenate 'string message "~C~C") value #\linefeed #\linefeed)
(force-output *query-io*))
(defun prompt-read (question)
(format *query-io* "~a: " question)
(read-line *query-io*)
(force-output *query-io*))
Run Code Online (Sandbox Code Playgroud)
运行可执行文件时,存在两个问题:
(status-update...)在读取最终提示之前执行。在终端中,问题出现但立即退出。所以我无法输入任何内容。(status-update...)值为。即使我在终端内输入了一个值。emailNIL整个过程在 repl 中完美运行。
注意 - 我正在使用 ASD MAKE 进程构建可执行文件。
(defun prompt-read (question)
(format *query-io* "~a: " question)
(read-line *query-io*)
(force-output *query-io*))
Run Code Online (Sandbox Code Playgroud)
将其更改为这样的内容:
(defun prompt-read (question)
(format *query-io* "~a: " question)
(force-output *query-io*)
(read-line *query-io*)
(force-output *query-io*))
Run Code Online (Sandbox Code Playgroud)
否则,当函数等待输入时,由于缓冲输出流,提示可能不可见。
流可能会也可能不会缓冲输出。对于可移植程序,您需要添加清除或强制输出的操作。
| 归档时间: |
|
| 查看次数: |
73 次 |
| 最近记录: |