How can I compare the lines the user entered?

I want to compare READ user input with a string, for example:

 CL-USER 36 > (equalp (read) "same") same NIL 

However, as you can see, although I type β€œthe same,” EQUALP says that my input and string are different. How can I compare these two?

+4
source share
1 answer

You can use read-line for this:

 CL-USER> (equalp (read-line) "same") same T 

read will return the character:

 CL-USER> (type-of (read)) same SYMBOL 

From Hyperspec :

read parses the printed representation of the object from the input stream and creates such an object.

You just want to read a string, while read parses the input and constructs Lisp objects from it.

To get the lines from read , you will need to use the "printed representation" of the lines, i.e. put them in double quotes:

 CL-USER> (equalp (read) "same") "same" T 

(BTW: to compare strings, string= ; equalp will ignore case.)

+5
source

All Articles