On 1/18/19 1:14 PM, Paulo Moura wrote:
> Hi,
>
> The documentation of the prompt/2 built-in predicate claims that "A prompt is printed if one of the read predicates is called and the cursor is at the left margin." But:
>
> ?- prompt(P, P).
> P = '|: '.
>
> ?- write('prompt: '), read(A), write('prompt: '), read(B), write('prompt: '), read(C).
> prompt: a.
> prompt: |: b.
> prompt: |: c.
>
> For the three read/1 calls above, the cursor is never at the left margin. But we only get the default prompt omitted for the first read/1 call. Is this a bug or am I misinterpreting at "left margin" means?
I did a little search. What happens is this:
- write('prompt: ') --> linepos = 8
- read(A) --> not at left margin: no prompt
--> BUT, according to the ISO standard, the
newline following the term is NOT read
--> linepos = 10 (assuming the user types "a.")
- write('prompt: ') --> linepos = 18
- read(B) --> first reads pending newline --> linepos = 0
Now at left margin: prompt
I think we had a discussion before on something related let to some hack
to make the toplevel behave more sensible.
I do not see a really good solution. One might be to ignore ISO and
read the blank following a term if the input is a terminal?
Using line editing though, just writing the prompt does not work as
the line editor thinks the cursor is at the left margin.
SWI-Prolog has a little bit oddly called predicate prompt1(+Text) that
avoids these problems.
Cheers --- Jan