[racket] REPL input chunking for non-sexp language

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Dec 10 10:04:07 EST 2012

When you run plain `racket', the REPL is `read-eval-print-loop', which
uses `(current-prompt-read)', `(current-eval)', and `(current-print)'.

Any line-editing capability is whatever the terminal does, which
normally means that input is sent to the reader when you hit Return.
Even if you load `readline' or `xrepl', a Return commits a line of
characters to be sent off to the reader.

The delivery of an expression to the evaluator, however, is determined
by the reader. That is, if your reader sees a "fun" that should match
an "end", then it should keep reading input characters until it sees
the "end". When the reader returns a datum, then it's passed off to the
evaluator.

(If an interactive EOF is needed to terminate a form for your reader,
that shouldn't necessarily make the REPL quit. The REPL should quit
only when the reader returns an EOF. So, a reader might consume an
interactive EOF as a terminator, and then it can continue reading the
next time around.)

If I remember correctly, DrRacket is a little different. A Return in
DrRacket takes the text so far and implicitly adds an EOF to the end.
If the reader applied to that text raises `exn:fail:read:eof', then
DrRacket it as an indication that the expression isn't finished, and so
it lets the user keep editing on the next line. Meanwhile, an
`exn:fail:read' exception other than the subtype `exn:fail:read:eof'
means that the read error should be reported to the user.


At Sun, 9 Dec 2012 19:03:44 -0500, Daniel Patterson wrote:
> I'm working (with sk and jpolitz) on a non-sexp language built on top
> of racket.
> 
> We have basic support for it in the repl inside DrRacket, but none at
> all from the racket commandline repl (which also means no support for
> embedding inside other editors) - and the former seems to be using
> s-exps to figure out when to send the input to our eval (I think - I
> haven't found documentation describing how this works).
> 
> So my question is:
> 
> Is there a way to specify how input is split before sending to eval,
> both so that DrRacket could follow our conventions (which might, for
> example, match a "fun" with matching "end"), and so that the
> commandline repl knows how to split input at all (as right now it just
> keeps waiting for input until EOF - and EOF also causes the repl to
> quit!) Is there something that read/read-syntax should signal, or another
> handler to use?
> 
> Thanks!
> Daniel
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.