public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Per Bothner <per@bothner.com>
To: kawa@sourceware.org, Helmut Eller <eller.helmut@gmail.com>
Subject: Re: Prompt on read
Date: Wed, 22 Nov 2017 21:27:00 -0000	[thread overview]
Message-ID: <964c1080-8e56-e60f-a3cd-f14eb12a44be@bothner.com> (raw)
In-Reply-To: <m28tezfbur.fsf@caladan>

On 11/22/2017 12:31 AM, Helmut Eller wrote:
> On Tue, Nov 21 2017, Per Bothner wrote:
> 
>>> 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 -
> 
> If a prompt is printed before each input line, then why does calling
> read-line not print a prompt?
> 
>> however note it is possible for a procedure to change the
>> prompt, for example to the empty string.

(After having to remind myself how it all works ...)

The interactive port does print a prompt at the beginning of line,
if there is a prompt specified.  However, the default prompt procedure
depends on the "read state" (i.e. input-port-read-state).  If
the read-state is #\newline (which is the default) the default prompt
string is empty (or actually null).  The read procedures sets the read-state
as it parses the S-expression.

Now consider:

$ bin/kawa console:use-jline=no
#|kawa:1|# (define r1 (read))
#|kawa:2|# (4 5)
#|kawa:2|# r1
(4 5)
#|kawa:3|#

Why is the line 2 prompt repeated?  I'm still trying to figure that out,
but it appears related to the fact that read doesn't read the entire line,
only the "(4 5)".  For example read followed by read-line to read
the remainder of the line works as expected.

#|kawa:3|# (define r2 (read)) (define l2 (read-line))
#|kawa:4|# (5 6)
#|kawa:5|# r2
(5 6)
#|kawa:6|# (write l2)
""
#|kawa:7|#

There are also some weirdness with console:use-jline=no (raw console read)
vs console:use-jline=yes (read using jline input library).

> You mean something like (fluid-let ((input-prompt1 "")) ...)  or
> something else?  Hmm, that would work for me.

That could work.
> 
>> 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.
> 
> Uhm, a REPL that wants to print its own prompt?

In which case you'd override the default prompt.

Or something like
> 
> (format #t "Please enter a filename: ")
> (open-output-file (read))

Here read-line makes sense but read is clearly wrong.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

  reply	other threads:[~2017-11-22 21:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-21 15:44 Helmut Eller
2017-11-21 22:49 ` Per Bothner
2017-11-21 23:31   ` Helmut Eller
2017-11-22 21:27     ` Per Bothner [this message]
2017-11-22 23:11       ` Helmut Eller
2017-11-26  3:32       ` Per Bothner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=964c1080-8e56-e60f-a3cd-f14eb12a44be@bothner.com \
    --to=per@bothner.com \
    --cc=eller.helmut@gmail.com \
    --cc=kawa@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).