mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 03:30:27 +02:00
flush whitespace from the repl input buffer *before* evaluation
* module/system/repl/repl.scm (start-repl): Given that the input port of the repl is line-buffered, it's likely we have #\newline in the input that is strictly extraneous, an in-band indicator to the repl that it should begin reading now. So flush out that newline, so that you can (read-char) at the repl, and it actually does wait for you to type in a char instead of just returning #\newline. While it's not an overriding concern, this does fix some brainfuck programs that want to input from the user.
This commit is contained in:
parent
b674d4716a
commit
0d646345f4
1 changed files with 14 additions and 0 deletions
|
@ -107,6 +107,9 @@
|
||||||
(newline)
|
(newline)
|
||||||
(set! status '()))
|
(set! status '()))
|
||||||
(else
|
(else
|
||||||
|
;; since the input port is line-buffered, consume up to the
|
||||||
|
;; newline
|
||||||
|
(flush-to-newline)
|
||||||
(with-backtrace
|
(with-backtrace
|
||||||
(catch 'quit
|
(catch 'quit
|
||||||
(lambda ()
|
(lambda ()
|
||||||
|
@ -134,3 +137,14 @@
|
||||||
((char-whitespace? ch) (read-char) (next-char wait))
|
((char-whitespace? ch) (read-char) (next-char wait))
|
||||||
(else ch)))
|
(else ch)))
|
||||||
#f))
|
#f))
|
||||||
|
|
||||||
|
(define (flush-to-newline)
|
||||||
|
(if (char-ready?)
|
||||||
|
(let ((ch (peek-char)))
|
||||||
|
(if (and (not (eof-object? ch)) (char-whitespace? ch))
|
||||||
|
(begin
|
||||||
|
(read-char)
|
||||||
|
(if (not (char=? ch #\newline))
|
||||||
|
(flush-to-newline)))))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue