i want to read 2 values from user input using lisp. I want to store those in variables so i can use them in my program.
So far i have the current code:
(defun le-posicao()
(let ((n_anel)
(pos_anel))
(princ "?")
(setf n_anel (read))
(setf pos_anel (read))
(when (and (integerp (n_anel)) (integerp (pos_anel)))
n_anel pos_anel)))
I’m creating the local variables with a let function and then i want to store the values i read from input in them.
My problem is, how can i read two values from input and store the first in one variable and the second in the other? The values are supposed to come in the following format:
? value1 value2
Can someone help me?
You’re trying to use Lisp imperatively. While this is possible, it may be slightly painful.
To make your code more functional, instead of creating variables and then mutating them, you should create names and bind values to them.
To clarify,
letis a special form, not a function; they are used to create lexically scoped bindings of names to values.I believe what you really want to do is:
This code avoids
setf.Notes:
Not sure about the parentheses in Common-Lisp’s
let— I’ve been using Clojure recently!Also not sure whether you’re using
readcorrectly.