From: Markus Triska Date: Sun, 7 Nov 2021 16:06:56 +0000 (+0100) Subject: express format/3 and portray_clause/2 in terms of phrase_to_stream/2 X-Git-Tag: v0.9.0~30^2~6 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=e32215e19adc87d8a6b43c357273a1d00ee78988;p=scryer-prolog.git express format/3 and portray_clause/2 in terms of phrase_to_stream/2 --- diff --git a/src/lib/format.pl b/src/lib/format.pl index db5eb48f..6962470e 100644 --- a/src/lib/format.pl +++ b/src/lib/format.pl @@ -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) },