[plt-scheme] read error handling in the repl

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Feb 26 16:01:21 EST 2008

At Tue, 26 Feb 2008 15:53:32 -0500, Doug Orleans wrote:
> I was curious about how infix operators were parsed, so I tried an
> experiment, but the results were stranger than I expected (note that I
> only typed the first line, the rest is MzScheme output):
> 
> > '(1 . < . 2 . < . 3)
> stdin::12: read: illegal use of `.'
> 
>  === context ===
> /usr/local/plt/collects/scheme/private/misc.ss:63:7
> 
> > #<procedure:<>
> > stdin::16: read: illegal use of "."
> 
>  === context ===
> /usr/local/plt/collects/scheme/private/misc.ss:63:7
> 
> > 3
> > stdin::19: read: unexpected `)'
> 
>  === context ===
> /usr/local/plt/collects/scheme/private/misc.ss:63:7
> 
> 
> Is this supposed to happen?  Why doesn't it keep reading until the
> matching close-paren before starting to eval again?

The reader always stops consuming input as soon as it discovers a
lexical error. And, in this case, the reader is sure that there's an
error as soon as it see the third delimited ".".

For better or worse, a similar effect happens with illegal escape
sequences in strings:

 > "aaa\Qbbb"
 readline::0: read: unknown escape sequence \Q in string

  === context ===
 /Users/mflatt/proj/plt/collects/scheme/private/misc.ss:63:7

 reference to undefined identifier: bbb

  === context ===
 /Users/mflatt/proj/plt/collects/scheme/private/misc.ss:63:7


Matthew



Posted on the users mailing list.