我不知道该怎么做。在以前的实现read-line
中是可用的,但由于某种原因它不在 Chez 中。
我如何只读取一行输入?
Chez Scheme 是 R6RS 的实现。使用 R6RSget-line
代替 R7RS read-line
。
我的标准前奏曲中有一条阅读线;它将行尾处理为回车、换行或两者中的任何一种顺序:
(define (read-line . port)
(define (eat p c)
(if (and (not (eof-object? (peek-char p)))
(char=? (peek-char p) c))
(read-char p)))
(let ((p (if (null? port) (current-input-port) (car port))))
(let loop ((c (read-char p)) (line '()))
(cond ((eof-object? c) (if (null? line) c (list->string (reverse line))))
((char=? #\newline c) (eat p #\return) (list->string (reverse line)))
((char=? #\return c) (eat p #\newline) (list->string (reverse line)))
(else (loop (read-char p) (cons c line)))))))