Merge pull request #222 from wasamasa/read-string-eof-behavior

read-string: return EOF if nothing can be read
This commit is contained in:
Justin Ethier 2017-09-07 13:07:47 -04:00 committed by GitHub
commit 8fe853dfac

View file

@ -645,21 +645,23 @@
(let ((port (if (null? opts) (let ((port (if (null? opts)
(current-input-port) (current-input-port)
(car opts)))) (car opts))))
(let loop ((acc '()) (if (eof-object? (peek-char port))
(i k) (eof-object)
(chr #f)) (let loop ((acc '())
(cond (i k)
((eof-object? chr) (chr #f))
(list->string (cond
(reverse acc))) ((eof-object? chr)
((zero? i) (list->string
(list->string (reverse acc)))
(reverse ((zero? i)
(if chr (cons chr acc) acc)))) (list->string
(else (reverse
(loop (if chr (cons chr acc) acc) (if chr (cons chr acc) acc))))
(- i 1) (else
(read-char port))))))) (loop (if chr (cons chr acc) acc)
(- i 1)
(read-char port))))))))
(define (flush-output-port . port) (define (flush-output-port . port)
(if (null? port) (if (null? port)
(Cyc-flush-output-port (current-output-port)) (Cyc-flush-output-port (current-output-port))