I am trying to write a custom current-read-interaction for a language with non-s-expression syntax, and I’m not sure I completely understand the protocol for how to detect the end of input across both the command line and DrRacket. I first wrote an implementation for DrRacket, which appears to continually call current-read-interaction until it returns #<eof>, at which point it presents the user a new prompt. Therefore, I simply decided to check char-available? on the provided port and return #<eof> whenever the port returned #f. This seems to work fine in DrRacket.
On the other hand, I found it does not work at all on the command line. Returning #<eof> on the command line just seems to kill the entire REPL. Furthermore, unlike DrRacket, the CLI does not seem to produce an EOF at the end of each expression, just a newline, re-using the same port each time. Checking for a newline in DrRacket would not work at all, though, because DrRacket permits entering multiline expressions in its REPL. This would lead me to believe that there are two completely different protocols for how the two different REPLs work: 1. In DrRacket, read all the contents in the port provided to current-read-interaction. Check the port against char-available? each call, and return #<eof> when it returns #f. 2. At the command line, read all contents up until a newline. Check the port against peek-char each call, and return #<eof> when it returns #<eof> to support exiting the REPL by sending ^D. These seem totally different, frustratingly so, since it seems like it would not be too hard for the CLI to use the same behavior as DrRacket. My guess is that I’m overcomplicating things at least a little, but I wasn’t able to locate anything about what exactly is expected of the function provided to current-read-interaction. Is there a way to implement it that can gracefully handle both scenarios? If not, what is the proper way to check if code is running in the CLI REPL or the DrRacket REPL and adjust behavior accordingly? Alexis -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.