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)))
精彩评论