开发者

how to take two input simultaneously in lisp?

I want to add two numbers that are to be ent开发者_如何转开发ered by the user in Lisp. How can I do that? I used the read command twice but it shows an error.


I recommend parsing numbers from user input with the parse-number library. Using read instead gives the user direct access to the Lisp reader, which you do not want.

Something like this should work:

(defun prompt-number (prompt &optional (prompt-stream *standard-output*)
                                       (read-stream *standard-input*))
  (format prompt-stream "~a: " prompt)
  (parse-number:parse-number (read-line read-stream)))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜