From: Markus Triska Date: Mon, 18 Mar 2024 20:43:30 +0000 (+0100) Subject: goal expansion for format/2 and format/3 X-Git-Tag: v0.10.0~150^2~2 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=58f7c94e7489d9cbb3d9ed8faed7c89c3e7413b4;p=scryer-prolog.git goal expansion for format/2 and format/3 In this way, we benefit from partial evaluation of format strings. --- diff --git a/src/lib/format.pl b/src/lib/format.pl index 2478e371..35d4fea2 100644 --- a/src/lib/format.pl +++ b/src/lib/format.pl @@ -451,9 +451,11 @@ digits(uppercase, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"). % advantage of this is that an ideal implementation writes the % characters as they become known, without manifesting the list. -format(Fs, Args) :- - current_output(Stream), - format(Stream, Fs, Args). +format(_, _) :- not_used. + +user:goal_expansion(format(Fs, Args), + ( current_output(Stream), + format(Stream, Fs, Args))). %% format(Stream, FormatString, Arguments) % @@ -461,9 +463,11 @@ format(Fs, Args) :- % binary stream, then the code of each emitted character must be in % 0..255. -format(Stream, Fs, Args) :- - phrase_to_stream(format_(Fs, Args), Stream), - flush_output(Stream). +format(_, _, _) :- not_used. + +user:goal_expansion(format(Stream, Fs, Args), + ( pio:phrase_to_stream(format:format_(Fs, Args), Stream), + flush_output(Stream))). /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?- phrase(format:cells("hello", [], 0, [], []), Cs).