From: Markus Triska Date: Sat, 14 Aug 2021 11:48:21 +0000 (+0200) Subject: ENHANCED: If N is omitted in ~Nr or ~NR, it defaults to 8. X-Git-Tag: v0.9.0~49^2 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=78c2f19e72ea890ff44cdaaac1c9209a39345063;p=scryer-prolog.git ENHANCED: If N is omitted in ~Nr or ~NR, it defaults to 8. This is for compatibility with Quintus, SICStus and GNU Prolog, addressing #1024. Example: ?- format("~r", [10]). %@ 12 true. --- diff --git a/src/lib/format.pl b/src/lib/format.pl index d873f2cc..ad9d40f7 100644 --- a/src/lib/format.pl +++ b/src/lib/format.pl @@ -31,6 +31,7 @@ ~Nr where N is an integer between 2 and 36: format the next argument, which must be an integer, in radix N. The characters "a" to "z" are used for radices 10 to 36. + If N is omitted, it defaults to 8 (octal). ~NR like ~Nr, except that "A" to "Z" are used for radices > 9 ~| place a tab stop at this position ~N| where N is an integer: place a tab stop at text column N @@ -55,7 +56,7 @@ If at all possible, format_//2 should be used, to stress pure parts that enable easy testing etc. If necessary, you can emit the list Ls - with maplist(write, Ls). + with maplist(put_char, Ls). The entire library only works if the Prolog flag double_quotes is set to chars, the default value in Scryer Prolog. This should @@ -249,11 +250,15 @@ cells([~|Fs0], Args0, Tab, Es, VNs) --> append(Bs, ['.'|Ds], Chars) ) }, cells(Fs, Args, Tab, [chars(Chars)|Es], VNs). +cells([~,r|Fs], Args, Tab, Es, VNs) --> !, + cells([~,'8',r|Fs], Args, Tab, Es, VNs). cells([~|Fs0], Args0, Tab, Es, VNs) --> { numeric_argument(Fs0, Num, [r|Fs], Args0, [Arg|Args]) }, !, { integer_to_radix(Arg, Num, lowercase, Cs) }, cells(Fs, Args, Tab, [chars(Cs)|Es], VNs). +cells([~,'R'|Fs], Args, Tab, Es, VNs) --> !, + cells([~,'8','R'|Fs], Args, Tab, Es, VNs). cells([~|Fs0], Args0, Tab, Es, VNs) --> { numeric_argument(Fs0, Num, ['R'|Fs], Args0, [Arg|Args]) }, !,