]> Repositorios git - scryer-prolog.git/commitdiff
use round brackets for goals involving operators
authorMarkus Triska <[email protected]>
Tue, 17 Dec 2024 21:51:47 +0000 (22:51 +0100)
committerMarkus Triska <[email protected]>
Tue, 17 Dec 2024 21:51:47 +0000 (22:51 +0100)
Examples:

    ?- portray_clause(((+) :- a=b,(-))).
    (+) :-
       a=b,
       (-).
       true.

    ?- portray_clause((a :- (b :- c))).
    a :-
       (b:-c).
       true.

This addresses #2715.

Currently, more round brackets than needed are emitted. Ideally, a
better approach to solve the issue here and also in toplevel.pl is
found in the future.

src/lib/format.pl

index 5389c90ddbe14c97a1d15008a176f734f40d49fd..2ac4744b8bd9c0ff99c12d06d81d44a315f08a31 100644 (file)
@@ -593,7 +593,15 @@ portray_clause_(Term) -->
 
 literal(Lit, VNs) -->
         { write_term_to_chars(Lit, [quoted(true),variable_names(VNs),double_quotes(true)], Ls) },
-        seq(Ls).
+        (   { nonvar(Lit),
+              functor(Lit, F, A),
+              current_op(Pri, _, F),
+              (   A =:= 0
+              ;   Pri >= 1000
+              ) } ->
+            "(", seq(Ls), ")"
+        ;   seq(Ls)
+        ).
 
 literal_(Lit, VNs) -->
         { phrase(literal(Lit, VNs), Ls) },