2

I can't find out how to do this. In previous implementations read-line was available but for some reason it isn't in Chez.

How do I just read a line of input?

2 Answers 2

3

Chez Scheme is the R6RS implementation. Use the R6RS get-line instead of the R7RS read-line.

3

I have a read-line in my Standard Prelude; it handles end-of-line as carriage-return, line-feed, or both in either order:

(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)))))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.