]> Repositorios git - scryer-prolog.git/commitdiff
express format/3 and portray_clause/2 in terms of phrase_to_stream/2
authorMarkus Triska <[email protected]>
Sun, 7 Nov 2021 16:06:56 +0000 (17:06 +0100)
committerMarkus Triska <[email protected]>
Sun, 7 Nov 2021 16:47:05 +0000 (17:47 +0100)
src/lib/format.pl

index db5eb48f3e4ff7ff6f2ad1bb96b7b50613d0c1e2..6962470ed0968d166c45cf3ea91d8f3176fc7ccb 100644 (file)
@@ -83,6 +83,7 @@
 :- use_module(library(error)).
 :- use_module(library(charsio)).
 :- use_module(library(between)).
+:- use_module(library(pio)).
 
 format_(Fs, Args) -->
         { must_be(list, Fs),
@@ -389,18 +390,7 @@ format(Fs, Args) :-
         format(Stream, Fs, Args).
 
 format(Stream, Fs, Args) :-
-        phrase(format_(Fs, Args), Cs),
-        (   stream_property(Stream, type(binary)) ->
-            (   '$first_non_octet'(Cs, N) ->
-                domain_error(byte_char, N, format/3)
-            ;   true
-            )
-        ;   true
-        ),
-        % we use a specialised internal predicate that uses only a
-        % single "write" operation for efficiency. It is equivalent to
-        % maplist(put_char(Stream), Cs). It also works for binary streams.
-        '$put_chars'(Stream, Cs),
+        phrase_to_stream(format_(Fs, Args), Stream),
         flush_output(Stream).
 
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -477,8 +467,8 @@ portray_clause(Term) :-
         portray_clause(Out, Term).
 
 portray_clause(Stream, Term) :-
-        phrase(portray_clause_(Term), Ls),
-        format(Stream, "~s", [Ls]).
+        phrase_to_stream(portray_clause_(Term), Stream),
+        flush_output(Stream).
 
 portray_clause_(Term) -->
         { unique_variable_names(Term, VNs) },