I am attempting to write a program whereby I need to process a string character-by-character, including whitespace. This string would be given by the user running the program, from the standard input stream.
I have noticed that the (read) function stops only after some non-whitespace characters have been captured, and cuts off everything starting with the first whitespace character.
In other words if I do a (read) function and enter hi to you, it will return HI. What I would like my function to return is (#\h #\i #\Space #\t #\o #\Space #\y #\o #\u). Can anyone give me some pointers as to how to accomplish this? Sorry guys, I am VERY new to LISP but I like it a lot.
EDIT: One thing I’ve tried is using (cons) with (read-char). For example: (cons (read-char) (cons (read-char) (cons (read-char) (cons (read-char) (read-char))))). When the user enters “hello”, this outputs (#\h #\e #\l #\l . #\o), which is close, but what is that extra period doing in there?
read-char will return the next available character, and read-line will return an entire line of input as a string. You can use coerce to change a string to a list of characters, e.g.