express format/3 and portray_clause/2 in terms of phrase_to_stream/2
:- 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) },
