]> Repositorios git - scryer-prolog.git/commitdiff
goal expansion for format/2 and format/3
authorMarkus Triska <[email protected]>
Mon, 18 Mar 2024 20:43:30 +0000 (21:43 +0100)
committerMarkus Triska <[email protected]>
Wed, 20 Mar 2024 20:10:14 +0000 (21:10 +0100)
In this way, we benefit from partial evaluation of format strings.

src/lib/format.pl

index 2478e3710c56dcee010a747621d44bbc9d666aee..35d4fea2be7513e9036e759f8fbd7008ed476630 100644 (file)
@@ -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).