mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
2.03k stars 118 forks source link

format: ~w and ~q write variables incorrectly #1095

Open UWN opened 2 years ago

UWN commented 2 years ago
?- format("~w\n",[X]).
A                    % unexpected, expected: start with _, as below
   true.
?- write(X),nl.
_1450236             % expected, a bit verbose though
   true.

~w should write a term using write/1. ~q should writeq it.

In above case both should use a2 for writing out a variable. Thus starting with an underscore and then some implementation dependent sequence.

It has been like that since the inception of format/2 and even in its predecessor writef/2. That is at least 1981.

triska commented 2 years ago

This is due to write_term_to_chars/3:

?- use_module(library(charsio)).
   true.
?- write_term_to_chars(X, [], Chars).
   Chars = "A".