Prompt on read

Per Bothner per@bothner.com
Tue Nov 21 22:49:00 GMT 2017


On 11/21/2017 04:44 PM, Helmut Eller wrote:
> Am I the only who finds it confusing that the read procedure
> automatically writes a prompt?  E.g.
> 
>    #|kawa:1|# (read)
>    #|kawa:2|# abc
>    abc
>    #|kawa:2|#

The read procedure does not write a prompt.
However, when you read from an "interactive port" (implemented using TtyInPort,
when a new line is requested, a prompt is printed.

In other words, in Kawa it's not the REPL that prints the prompt,
but the port itself.

This has the advantage that multi-line input commands get multiple =prompts,
which I think is the correct behavior.

> Despite that the prompt in line two is confusing, the line number in the
> third prompt seems wrong.  I would expect that read works basically like
> read-line,

Yes and no.  read reads an S-expression, and there may be a many-to-many
relationship between S-expressions and lines.  A prompt is printed before
each input line - however note it is possible for a procedure to change the
prompt, for example to the empty string.

I agree there does appear to be some mismatch between when a line number
is incremented and a prompt is printed.  This is at least ugly.
I haven't looked into why that happens.

FWIW I can't come up with any valid use-case for explicitly calling read on an
interactive port.  The problem is error recovery.  Enlighten me.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/



More information about the Kawa mailing list