开发者

how to take two input simultaneously in lisp?

开发者 https://www.devze.com 2023-03-05 03:22 出处:网络
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

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

精彩评论

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