ENHANCED: format_//2, format/[2,3], portray_clause/1 are now deterministic.

This works as soon as #732 is merged, since then maplist/N and foldl/N
are deterministic in the required cases.

This also resolves the extra choicepoint of time/1 (see #378).

Many thanks to @notoria for implementing better indexing in #732,
which allowed me to find this opportunity for improvement!
This commit is contained in:
Markus Triska
2020-12-19 18:07:43 +01:00
parent 22ffb1f53f
commit 4efbc20a4f

View File

@@ -158,7 +158,7 @@ element_gluevar(glue(_,V), N, N) --> [V].
consume whitespace in the sense of format strings. consume whitespace in the sense of format strings.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
cells([], Args, Tab, Es, _) --> cells([], Args, Tab, Es, _) --> !,
( { Args == [] } -> cell(Tab, Tab, Es) ( { Args == [] } -> cell(Tab, Tab, Es)
; { domain_error(empty_list, Args, format_//2) } ; { domain_error(empty_list, Args, format_//2) }
). ).
@@ -404,32 +404,28 @@ Cs = [cell(0,4,[glue(' ',_A),chars("a"),glue(' ',_B)])]
?- phrase(format_("hello~n~tthere~6|", []), Ls). ?- phrase(format_("hello~n~tthere~6|", []), Ls).
?- format("~ta~t~4|", []). ?- format("~ta~t~4|", []).
a true a true.
; false.
?- format("~ta~tb~tc~10|", []). ?- format("~ta~tb~tc~10|", []).
a b c true a b c true.
; false.
?- format("~tabc~3|", []). ?- format("~tabc~3|", []).
?- format("~ta~t~4|", []). ?- format("~ta~t~4|", []).
?- format("~ta~t~tb~tc~20|", []). ?- format("~ta~t~tb~tc~20|", []).
a b c true a b c true.
; false.
?- format("~2f~n", [3]). ?- format("~2f~n", [3]).
3.00 3.00
true true.
?- format("~20f", [0.1]). ?- format("~20f", [0.1]).
0.10000000000000000000 true % this should use higher accuracy! 0.10000000000000000000 true.
; false.
?- X is atan(2), format("~7f~n", [X]). ?- X is atan(2), format("~7f~n", [X]).
1.1071487 1.1071487
X = 1.1071487177940906 X = 1.1071487177940906.
?- format("~`at~50|~n", []). ?- format("~`at~50|~n", []).
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
@@ -438,10 +434,10 @@ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
?- format("~t~N", []). ?- format("~t~N", []).
?- format("~q", [.]). ?- format("~q", [.]).
'.' true '.' true.
?- format("~12r", [300]). ?- format("~12r", [300]).
210 true 210 true.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -537,7 +533,7 @@ a :-
b, b,
c, c,
d. d.
true true.
?- portray_clause([a,b,c,d]). ?- portray_clause([a,b,c,d]).