clasp icon indicating copy to clipboard operation
clasp copied to clipboard

read-char does not work at the repl

Open stassats opened this issue 9 years ago • 7 comments

(read-char) immediately returns #\LINEFEED

stassats avatar Jul 13 '15 15:07 stassats

Can confirm on b05884f.

> (read-char)

#\LINEFEED

Shinmera avatar Sep 25 '15 20:09 Shinmera

Failure changed on 99669d674a6f2b7ce0a9127cf6537fc03066baa5

> (read-char)

#\NEWLINE

Shinmera avatar Sep 01 '16 08:09 Shinmera

Fixed this here 67edc9984b9f69a7c6f2faaded0d43f1b9693eda

drmeister avatar Mar 13 '18 02:03 drmeister

The previous fix was not sufficient - it caused other problems. Here is another attempt: d375df2b98219e16d4b72a2ef19308ef22413673

drmeister avatar Mar 17 '18 23:03 drmeister

Bleh - there are still problems here.

I try the following... I hit Ctrl-D once and the following happens.

COMMON-LISP-USER> (loop for x below 10 for in = (read-line standard-input nil :eof) do (format t "read |~s|~%" in)) Writing jitted symbols to /tmp/clasp-symbols-11298 read |""| read |:EOF| read |:EOF| read |:EOF| read |:EOF| read |:EOF| read |:EOF| read |:EOF| read |:EOF| read |:EOF| NIL COMMON-LISP-USER>

drmeister avatar Mar 28 '19 13:03 drmeister

COMMON-LISP-USER>>>  (read-char)
#\Newline

kpoeck avatar May 08 '19 21:05 kpoeck

The problem actually seems to be like... it's not eating whitespace?

What it's actually doing is grabbing the next character from the stream, apparently. For example, if you enter (read-char)f on the repl, you get #\f, as you might expect. But if it hits the end of the line it reads a newline instead of waiting. So (values (read-char) (read-char))f => #\f, #\Newline, and (values (read-char) (read-char)) will wait for you to input a character, and then return a newline and whatever you entered.

So I think the problem isn't actually the reader so much as the repl? Maybe?

Bike avatar Mar 11 '20 13:03 Bike