Portray_text/1 with one or two characters doesn't portray text?

Here’s my file:

:-module(abcd,[abcd//0
              ,a//0
              ,ab//0
              ,abc//0
              ,abcd//0]).

a --> `a`.
ab --> `ab`.
abc --> `abc`.
abcd --> `abcd`.

And here’s a few queries:

103 ?- current_prolog_flag(answer_write_options,Vs).
Vs = [quoted(true),portray(true),max_depth(20),attributes(portray),numbervars(true)].

104 ?- current_prolog_flag(back_quotes,V).
V = codes.

105 ?- portray_text(true).
true.

106 ?- phrase(abcd:a, P).
P = [97].

107 ?- phrase(abcd:ab, P).
P = [97,98].

108 ?- phrase(abcd:abc, P).
P = `abc`.

109 ?- phrase(abcd:abcd, P).
P = `abcd`.

This seems wrong? I believe back-quoted codes should be portrayed as text regardless of length?

Forgot to say: this is yesterday’s latest build for windows 0.1.5-2-gc829d651e-DIRTY, 64 bits, on a windows 11 machine .

Note that it is ambiguous whether a list of integers is text or not. The heuristics use the length (>=3) and demands each character to be TAB, NL, CR or a printable ASCII character. You can extend the accepted characters by defining clauses for portray_text:is_text_code/1 and the minimum length using e.g.,

?- set_portray_text(min_length, 1).

set_portray_text/2 also controls when the string is abbreviated using ellipsis.

That is as good as it gets :frowning: Note that this gets really hard for Unicode …

2 Likes
min_length
    Only consider for conversion lists of integers that have a length of at least Value. Default is 3.

I was squinting hard at that documentation for like half an hour and I totally managed to miss that completely. :woman_facepalming:

I also don’t understand how I missed that before because I have many instances of single-character back-quoted lists in my code. Odd.

Anyway, let’s see if that helps. Thanks @jan.