2

我不知道该怎么做。在以前的实现read-line中是可用的,但由于某种原因它不在 Chez 中。

我如何只读取一行输入?

4

2 回答 2

3

Chez Scheme 是 R6RS 的实现。使用 R6RSget-line代替 R7RS read-line

于 2017-04-07T20:04:42.840 回答
2

我的标准前奏曲中有一条阅读线;它将行尾处理为回车、换行或两者中的任何一种顺序:

(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)))))))
于 2016-06-16T12:48:46.873 回答