Open UWN opened 1 year ago
And here it is perfect:
?- length(L,N), write_term(L,[max_depth(3)]).
[] L = [], N = 0
; [_13] L = [_A], N = 1
; [_13,_18] L = [_A,_B], N = 2
; [_13,_18,_23] L = [_A,_B,_C], N = 3
; [_13,_18,_23|...] L = [_A,_B,_C,_D], N = 4
; ... .
Trealla Prolog (c) Infradig 2020-2023, v2.21.31
?- write_term(t,[max_depth(-1)]).
error(domain_error(write_option,max_depth(-1)),write_term/2).
t?-
^^ unexpected t
Sorry, fixed now. Only the first part of issue though, not the ... part.
On Mon, Jul 10, 2023 at 6:26 PM UWN @.***> wrote:
Trealla Prolog (c) Infradig 2020-2023, v2.21.31 ?- write_term(t,[max_depth(-1)]). error(domain_error(write_option,max_depth(-1)),write_term/2). t?- ^^ unexpected t
— Reply to this email directly, view it on GitHub https://github.com/trealla-prolog/trealla/issues/250#issuecomment-1628487096, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFNKSETV7WTQFO65UU2TDWTXPO4DLANCNFSM6AAAAAA2EDPZWM . You are receiving this because you commented.Message ID: @.***>
Pushed tests for this de facto standard option (of the Prolog systems supported by Logtalk, only B-Prolog, CxProlog, and JIProlog fail to support it):
$ logtalk_tester -p trealla -s Documents/Logtalk/
% Batch testing started @ 2023-07-10 10:20:44
% Logtalk version: 3.68.0-b01
% Trealla Prolog version: 2.21.32
%
% /Users/pmoura/Documents/Logtalk/logtalk3/tests/prolog/predicates/write_term_3
% 130 tests: 0 skipped, 130 passed, 0 failed (0 flaky)
% completed tests from object tests in 2 seconds
% clause coverage n/a
%
% 1 test sets: 1 completed, 0 skipped, 0 broken, 0 timedout, 0 crashed
% 130 tests: 0 skipped, 130 passed, 0 failed (0 flaky)
%
% Batch testing ended @ 2023-07-10 10:20:47
The main difference I found in error-checking is with negative depth values. Ciao Prolog, LVM, SICStus Prolog, Trealla Prolog, and XSB throw a domain error. But others like ECLiPSe, GNU Prolog, and SWI-Prolog accept them. YAP doesn't try to type-check the depth.
?- D=3,write_term([1,2,3,4],[max_depth(3)]). [1,2,3|...] D = 3. % OK ?- D=3,write_term([1,2,3,4],[max_depth(D)]). [1,2,3,4] D = 3, unexpected.
Fix pushed for this, used wrong issue # in commit.
On Mon, 10 July 2023, 20:27 UWN, @.***> wrote:
?- D=3,write_term([1,2,3,4],[max_depth(3)]). [1,2,3|...] D = 3. % OK ?- D=3,write_term([1,2,3,4],[max_depth(D)]). [1,2,3,4] D = 3, unexpected.
— Reply to this email directly, view it on GitHub https://github.com/trealla-prolog/trealla/issues/250#issuecomment-1628666875, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFNKSESVU3E5SVB5RKKXWEDXPPKK7ANCNFSM6AAAAAA2EDPZWM . You are receiving this because you commented.Message ID: @.***>
Taking the observations from https://github.com/didoudiaz/gprolog/issues/56
The printed term is exactly like the original term with some non-variable subterms replaced by the atom ...
When replacing the atom ...
by fresh new variables, the resulting term has the original term as an instance.
The 2nd point now works, the first not.
Here is a comparison with SICStus which seems the way to go except for 4-1:
?- nth1(I,[1+2+3+4,_^_^_^_^_,1^2^3^4^nil,[1,2,3,4],[_,_,_,_]],T),
between(0,5,D), write(I-D), write(' '), write_term(T,[max_depth(D)]), nl, false.
% SICStus % Trealla
1-0 1+2+3+4 1-0 1+2+3+4
1-1 ... + ... 1-1 ... + ...
1-2 ... + ... +4 1-2 ... + ... +4
1-3 ... + ... +3+4 1-3 ... + ... +3+4
1-4 1+2+3+4 1-4 1+2+3+4
1-5 1+2+3+4 1-5 1+2+3+4
2-0 _1143^_1179^_1215^_1251^_1287 2-0 _1^_2^_3^_4^_5
2-1 _1143^ ... 2-1 ... ^ ...
2-2 _1143^_1179^ ... 2-2 _1^ ... ^ ...
2-3 _1143^_1179^_1215^ ... 2-3 _1^_2^ ... ^ ...
2-4 _1143^_1179^_1215^_1251^_1287 2-4 _1^_2^_3^ ... ^ ...
2-5 _1143^_1179^_1215^_1251^_1287 2-5 _1^_2^_3^_4^_5
3-0 1^2^3^4^nil 3-0 1^2^3^4^nil
3-1 ... ^ ... 3-1 ... ^ ...
3-2 1^ ... ^ ... 3-2 1^ ... ^ ...
3-3 1^2^ ... ^ ... 3-3 1^2^ ... ^ ...
3-4 1^2^3^ ... ^ ... 3-4 1^2^3^ ... ^ ...
3-5 1^2^3^4^nil 3-5 1^2^3^4^nil
4-0 [1,2,3,4] 4-0 [1,2,3,4]
4-1 [...|...] 4-1 [...|...] Suggested: [1|...]
4-2 [1,2|...] 4-2 [...,...|...]
4-3 [1,2,3|...] 4-3 [1,2,3|...]
4-4 [1,2,3,4] 4-4 [1,2,3,4]
4-5 [1,2,3,4] 4-5 [1,2,3,4]
5-0 [_1581,_1613,_1645,_1677] 5-0 [_6,_7,_8,_9]
5-1 [_1581|...] 5-1 [...|...]
5-2 [_1581,_1613|...] 5-2 [...,...|...]
5-3 [_1581,_1613,_1645|...] 5-3 [_6,_7,_8|...]
5-4 [_1581,_1613,_1645,_1677] 5-4 [_6,_7,_8,_9]
5-5 [_1581,_1613,_1645,_1677] 5-5 [_6,_7,_8,_9]
Trealla Prolog (c) Infradig 2020-2023, v2.21.31 ?- write_term(t,[max_depth(-1)]). error(domain_error(write_option,max_depth(-1)),write_term/2). t?- ^^ unexpected t
Added a test for this unexpected output. With v2.22.0 (916748d49aae5f8bcfedc27eb4a49653c6f5c376), this and other new tests all pass:
$ logtalk_tester -p trealla -s ~/Documents/Logtalk/
% Batch testing started @ 2023-07-11 11:02:59
% Logtalk version: 3.68.0-b01
% Trealla Prolog version: 2.22.0
%
% logtalk3/tests/prolog/predicates/write_term_3
% 134 tests: 0 skipped, 134 passed, 0 failed (0 flaky)
% completed tests from object tests in 1 second
% clause coverage n/a
%
% 1 test sets: 1 completed, 0 skipped, 0 broken, 0 timedout, 0 crashed
% 134 tests: 0 skipped, 134 passed, 0 failed (0 flaky)
%
% Batch testing ended @ 2023-07-11 11:03:02
``
Now:
?- nth0(I,[A+B+C+D,1+2+3+4,A^B^C^D^E,1^2^3^4^nil,[1,2,3,4],[A,B,C,D],[- -A,- -B,- -C,- -D],[[A,B,C,D]],[[[[[A,B,C,D]]]]]],T),
between(0,5,M), write(I-M), write(' '),
write_term(T,[variable_names(['A'=A,'B'=B,'C'=C,'D'=D,'E'=E]),max_depth(M)]), nl, false.
SICStus Trealla
0-0 A+B+C+D 0-0 A+B+C+D
0-1 ... +D 0-1 ... + ...
0-2 ... +C+D 0-2 ... + ... +D
0-3 A+B+C+D 0-3 ... + ... +C+D
0-4 A+B+C+D 0-4 A+B+C+D
0-5 A+B+C+D 0-5 A+B+C+D
1-0 1+2+3+4 1-0 1+2+3+4
1-1 ... + ... 1-1 ... + ...
1-2 ... + ... +4 1-2 ... + ... +4
1-3 ... + ... +3+4 1-3 ... + ... +3+4
1-4 1+2+3+4 1-4 1+2+3+4
1-5 1+2+3+4 1-5 1+2+3+4
2-0 A^B^C^D^E 2-0 A^B^C^D^E
2-1 A^ ... 2-1 ... ^ ...
2-2 A^B^ ... 2-2 A^ ... ^ ...
2-3 A^B^C^ ... 2-3 A^B^ ... ^ ...
2-4 A^B^C^D^E 2-4 A^B^C^ ... ^ ...
2-5 A^B^C^D^E 2-5 A^B^C^D^E
3-0 1^2^3^4^nil 3-0 1^2^3^4^nil
3-1 ... ^ ... 3-1 ... ^ ...
3-2 1^ ... ^ ... 3-2 1^ ... ^ ...
3-3 1^2^ ... ^ ... 3-3 1^2^ ... ^ ...
3-4 1^2^3^ ... ^ ... 3-4 1^2^3^ ... ^ ...
3-5 1^2^3^4^nil 3-5 1^2^3^4^nil
4-0 [1,2,3,4] 4-0 [1,2,3,4]
4-1 [...|...] 4-1 [1|...]
4-2 [1,2|...] 4-2 [1,2|...]
4-3 [1,2,3|...] 4-3 [1,2,3|...]
4-4 [1,2,3,4] 4-4 [1,2,3,4]
4-5 [1,2,3,4] 4-5 [1,2,3,4]
5-0 [A,B,C,D] 5-0 [A,B,C,D]
5-1 [A|...] 5-1 [A|...]
5-2 [A,B|...] 5-2 [A,B|...]
5-3 [A,B,C|...] 5-3 [A,B,C|...]
5-4 [A,B,C,D] 5-4 [A,B,C,D]
5-5 [A,B,C,D] 5-5 [A,B,C,D]
6-0 [- -A,- -B,- -C,- -D] 6-0 [- -A,- -B,- -C,- -D]
6-1 [...|...] 6-1 [- ...|...]
6-2 [- ...,- ...|...] 6-2 [- ...,- ...|...]
6-3 [- -A,- -B,- ...|...] 6-3 [- ...,- ...,- ...|...]
6-4 [- -A,- -B,- -C,- ...] 6-4 [- -...,- -...,- -...,- -...]
6-5 [- -A,- -B,- -C,- -D] 6-5 [- -A,- -B,- -C,- -D]
7-0 [[A,B,C,D]] 7-0 [[A,B,C,D]]
7-1 [...] 7-1 [[...|...]]
7-2 [[A|...]] 7-2 [[...,...|...]]
7-3 [[A,B|...]] 7-3 [[A,B,C|...]]
7-4 [[A,B,C|...]] 7-4 [[A,B,C,D]]
7-5 [[A,B,C,D]] 7-5 [[A,B,C,D]]
8-0 [[[[[A,B,C,D]]]]] 8-0 [[[[[A,B,C,D]]]]]
8-1 [...] 8-1 [[...]]
8-2 [[...]] 8-2 [[...]]
8-3 [[[...]]] 8-3 [[[...]]]
8-4 [[[[...]]]] 8-4 [[[...]]]
8-5 [[[[[A|...]]]]] 8-5 [[[[...]]]]
Do you really intend to replace variables by ...
? It starts with 0-1... 4-1 is definitely an improvement. But what happens in 8 is not clear to me at all, with increasing depth, also the lists should resurface, one by one.
It's ongoing work.
On Thu, 13 July 2023, 13:29 UWN, @.***> wrote:
Now:
?- nth0(I,[A+B+C+D,1+2+3+4,A^B^C^D^E,1^2^3^4^nil,[1,2,3,4],[A,B,C,D],[- -A,- -B,- -C,- -D],[[A,B,C,D]],[[[[[A,B,C,D]]]]]],T), between(0,5,M), write(I-M), write(' '), write_term(T,[variable_names(['A'=A,'B'=B,'C'=C,'D'=D,'E'=E]),max_depth(M)]), nl, false.
SICStus Trealla 0-0 A+B+C+D 0-0 A+B+C+D 0-1 ... +D 0-1 ... + ... 0-2 ... +C+D 0-2 ... + ... +D 0-3 A+B+C+D 0-3 ... + ... +C+D 0-4 A+B+C+D 0-4 A+B+C+D 0-5 A+B+C+D 0-5 A+B+C+D 1-0 1+2+3+4 1-0 1+2+3+4 1-1 ... + ... 1-1 ... + ... 1-2 ... + ... +4 1-2 ... + ... +4 1-3 ... + ... +3+4 1-3 ... + ... +3+4 1-4 1+2+3+4 1-4 1+2+3+4 1-5 1+2+3+4 1-5 1+2+3+4 2-0 A^B^C^D^E 2-0 A^B^C^D^E 2-1 A^ ... 2-1 ... ^ ... 2-2 A^B^ ... 2-2 A^ ... ^ ... 2-3 A^B^C^ ... 2-3 A^B^ ... ^ ... 2-4 A^B^C^D^E 2-4 A^B^C^ ... ^ ... 2-5 A^B^C^D^E 2-5 A^B^C^D^E 3-0 1^2^3^4^nil 3-0 1^2^3^4^nil 3-1 ... ^ ... 3-1 ... ^ ... 3-2 1^ ... ^ ... 3-2 1^ ... ^ ... 3-3 1^2^ ... ^ ... 3-3 1^2^ ... ^ ... 3-4 1^2^3^ ... ^ ... 3-4 1^2^3^ ... ^ ... 3-5 1^2^3^4^nil 3-5 1^2^3^4^nil 4-0 [1,2,3,4] 4-0 [1,2,3,4] 4-1 [...|...] 4-1 [1|...] 4-2 [1,2|...] 4-2 [1,2|...] 4-3 [1,2,3|...] 4-3 [1,2,3|...] 4-4 [1,2,3,4] 4-4 [1,2,3,4] 4-5 [1,2,3,4] 4-5 [1,2,3,4] 5-0 [A,B,C,D] 5-0 [A,B,C,D] 5-1 [A|...] 5-1 [A|...] 5-2 [A,B|...] 5-2 [A,B|...] 5-3 [A,B,C|...] 5-3 [A,B,C|...] 5-4 [A,B,C,D] 5-4 [A,B,C,D] 5-5 [A,B,C,D] 5-5 [A,B,C,D] 6-0 [- -A,- -B,- -C,- -D] 6-0 [- -A,- -B,- -C,- -D] 6-1 [...|...] 6-1 [- ...|...] 6-2 [- ...,- ...|...] 6-2 [- ...,- ...|...] 6-3 [- -A,- -B,- ...|...] 6-3 [- ...,- ...,- ...|...] 6-4 [- -A,- -B,- -C,- ...] 6-4 [- -...,- -...,- -...,- -...] 6-5 [- -A,- -B,- -C,- -D] 6-5 [- -A,- -B,- -C,- -D] 7-0 [[A,B,C,D]] 7-0 [[A,B,C,D]] 7-1 [...] 7-1 [[...|...]] 7-2 [[A|...]] 7-2 [[...,...|...]] 7-3 [[A,B|...]] 7-3 [[A,B,C|...]] 7-4 [[A,B,C|...]] 7-4 [[A,B,C,D]] 7-5 [[A,B,C,D]] 7-5 [[A,B,C,D]] 8-0 [[[[[A,B,C,D]]]]] 8-0 [[[[[A,B,C,D]]]]] 8-1 [...] 8-1 [[...]] 8-2 [[...]] 8-2 [[...]] 8-3 [[[...]]] 8-3 [[[...]]] 8-4 [[[[...]]]] 8-4 [[[...]]] 8-5 [[[[[A|...]]]]] 8-5 [[[[...]]]]
Do you really intend to replace variables by ...? It starts with 0-1... 4-1 is definitely an improvement. But what happens in 8 is not clear to me at all, with increasing depth, also the lists should resurface, one by one.
— Reply to this email directly, view it on GitHub https://github.com/trealla-prolog/trealla/issues/250#issuecomment-1633493091, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFNKSEX5VHULVXENXUB66YDXP5TRXANCNFSM6AAAAAA2EDPZWM . You are receiving this because you commented.Message ID: @.***>
This is currently an implementation specific extension, but it is handled incorrectly: