Read reference:
read-char: "Reads a single character from in
– which may involve reading several bytes to UTF-8-decode them into a character. If no bytes are available before an end-of-file, then eof
is returned."
read-string: "Returns a string containing the next amt
characters from in
. If no characters are available before an end-of-file, then eof
is returned."
Examples:
> (read-char (open-input-string "char"))
#\c
> (read-string 50 (open-input-string "the string"))
"the string"
>
But if there are no character(s) in the buffer, you'll get eof
:
> (read-char (open-input-string ""))
#<eof>
> (read-string 50 (open-input-string ""))
#<eof>
I think you just want to read some amount of characters in a loop and do something with them. If so, the solution would look something along the lines of:
(define (another-process inp)
(let ([c (read-char inp)])
(if (eof-object? c)
(begin (display "==== EOF ====") (newline))
(begin (display c) (newline)
(another-process inp)))))
Example:
> (another-process (open-input-string "OK"))
O
K
==== EOF ====
> (another-process (open-input-string ""))
==== EOF ====
>
Notice a second call to another-process
with an empty line, it detects eof
immediately and exits the loop.
EDIT:
In case you need to check if the read character is newline:
(define (process-moo inp)
(let ([c (read-char inp)])
(cond
((eof-object? c)
(display "==== EOF ====") (newline))
((eq? c #\newline)
(newline) (display "---- NEWLINE ----") (newline)
(process-moo inp))
(else
(display c)
(process-moo inp)))))
Example:
> (call-with-input-string "Hello\nhumans\n!" process-moo)
Hello
---- NEWLINE ----
humans
---- NEWLINE ----
!==== EOF ====
>
Hope that helps.