express format/3 and portray_clause/2 in terms of phrase_to_stream/2

This commit is contained in:
Markus Triska
2021-11-07 17:06:56 +01:00
parent 893fb0e3cc
commit e32215e19a

View File

@@ -83,6 +83,7 @@
:- use_module(library(error)). :- use_module(library(error)).
:- use_module(library(charsio)). :- use_module(library(charsio)).
:- use_module(library(between)). :- use_module(library(between)).
:- use_module(library(pio)).
format_(Fs, Args) --> format_(Fs, Args) -->
{ must_be(list, Fs), { must_be(list, Fs),
@@ -389,18 +390,7 @@ format(Fs, Args) :-
format(Stream, Fs, Args). format(Stream, Fs, Args).
format(Stream, Fs, Args) :- format(Stream, Fs, Args) :-
phrase(format_(Fs, Args), Cs), phrase_to_stream(format_(Fs, Args), Stream),
( 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),
flush_output(Stream). flush_output(Stream).
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -477,8 +467,8 @@ portray_clause(Term) :-
portray_clause(Out, Term). portray_clause(Out, Term).
portray_clause(Stream, Term) :- portray_clause(Stream, Term) :-
phrase(portray_clause_(Term), Ls), phrase_to_stream(portray_clause_(Term), Stream),
format(Stream, "~s", [Ls]). flush_output(Stream).
portray_clause_(Term) --> portray_clause_(Term) -->
{ unique_variable_names(Term, VNs) }, { unique_variable_names(Term, VNs) },