summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2009-06-22 22:57:48 +0200
committerAndy Wingo <wingo@pobox.com>2009-06-22 22:57:48 +0200
commit0d646345f477f0ffced6f602370fc8c607f7d32f (patch)
tree26314319593087ca042e363ceda6846ed7741713
parentb674d4716abe775e648445795f02bece8a3396e0 (diff)
downloadguile-0d646345f477f0ffced6f602370fc8c607f7d32f.tar.gz
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.
-rw-r--r--module/system/repl/repl.scm14
1 files changed, 14 insertions, 0 deletions
diff --git a/module/system/repl/repl.scm b/module/system/repl/repl.scm
index 86fb56fd2..2f4a3783a 100644
--- a/module/system/repl/repl.scm
+++ b/module/system/repl/repl.scm
@@ -107,6 +107,9 @@
(newline)
(set! status '()))
(else
+ ;; since the input port is line-buffered, consume up to the
+ ;; newline
+ (flush-to-newline)
(with-backtrace
(catch 'quit
(lambda ()
@@ -134,3 +137,14 @@
((char-whitespace? ch) (read-char) (next-char wait))
(else ch)))
#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)))))))
+
+ \ No newline at end of file