[racket-dev] current-read-interaction

From: Jon Rafkind (rafkind at cs.utah.edu)
Date: Thu Sep 15 18:05:58 EDT 2011

For Honu I set up the `current-read-interaction' procedure to read a string of characters ended by a newline and to parse that with `honu-read-syntax'. This
leads to two issues

1. this works on the command line but in drracket after typing '1' and pressing enter the prompt never comes back and drracket chews up some cpu.
2. I wanted to make ctrl-d quit the repl immediately so I look for an eof-object in the stream and if found I try to return #'(exit). The Honu parser gets
involved at that point so it doesn't quite work, but anyway is that the right strategy?

Here is my repl reader:

(define (read-one-line name input)
  (define quit? #f)
  (define one-line
      (lambda ()
        (let loop ()
          (define next (read-char input))
          (when (eof-object? next)
            (set! quit? #t))
          (when (not (or (eof-object? next)
                         (char=? next #\newline)))
            (display next)
  (if quit?
    ;; this isn't right, somehow communicate to the system that the repl should close
    (honu-read-syntax name (open-input-string one-line))))

(provide configure)
(define (configure . args)
  (current-read-interaction read-one-line))

Posted on the dev mailing list.