scryer-prolog
scryer-prolog copied to clipboard
Wrong output of write_term/2, max_depth/1
?- A = [A|c], write_term(A,[max_depth(0)]),nl.
[...|c]
A = [A|c].
?- A = [A|c], write_term(A,[max_depth(1)]),nl.
[...|...]
A = [A|c].
?- A = [A|c], write_term(A,[max_depth(2)]),nl.
[c,...|...] % unexpected
A = [A|c].
?- A = [A|c], write_term(A,[max_depth(3)]),nl.
[c,c,...|...] % unexpected
A = [A|c].
?-
For example: [c,c,..|...] should be displayed like so [c,c,...|c] ?
EDIT: ... like so [[[...]|c]|c] ?
Let's first unfold the term for a few levels:
?- A = [A|c], A == [[A|c]|c], A == [[[A|c]|c]|c], A == [[[[A|c]|c]|c]|c]. A = [A|c].
So, A
in this example is not of the shape [c|...]
, and therefore the cases where the output starts with [c
are wrong output.
?- A = [A|c], A = [c|_]. false.
The output must truthfully capture the shape of the term.
Like SWI does:
?- A = [A|c], write_term(A,[max_depth(6)]),nl.
[[[[[[...|...]|...]|c]|c]|c]|c]
So output should not start with [c and should end with |c] (after a certain depth)
A much cleaner approach would be to first transform the term to a term that contains the atom ...
at certain places and then to display it. There is a lot of code in Rust which does not belong there.
Like GNU then: | ?- A = [A|c], write_term(A,[max_depth(3)]),nl. [[[...]|c]|c]
Is it a good idea that [...]
stands here for a non-list? The term A = [A|c]
does not contain any list. [[...|c]|c]
might be a better abbreviation. (These abbreviations are everywhere a chaos)
So, someone can say the term contains list notation.
It means that one cannot transform a term to an abbreviated term just by replacing in adequate positions some terms by the atom ...
. In stead, much more is happening. And every system does it differently.
I think, following the pattern of how Scryer does things like the toplevel, that the thing we should do here is the one that is more close to actual Prolog and transformations of it. So I support the idea @UWN gave of doing some term substitution in Prolog for the implementation.