]> Repositorios git - scryer-prolog.git/commitdiff
bracket all operators that are direct operands of (=)/2
authorMarkus Triska <[email protected]>
Fri, 30 Jun 2023 05:34:15 +0000 (07:34 +0200)
committerMarkus Triska <[email protected]>
Fri, 30 Jun 2023 06:03:38 +0000 (08:03 +0200)
This addresses #804.

src/toplevel.pl

index b554e52c48281c7bb63fb819684f43878729ef01..ff4638335f252028e906e757dc82d8b782c83bfe 100644 (file)
@@ -205,12 +205,14 @@ submit_query_and_print_results(Term, VarList) :-
 
 
 needs_bracketing(Value, Op) :-
-    catch((functor(Value, F, _),
-           current_op(EqPrec, EqSpec, Op),
-           current_op(FPrec, _, F)),
-          _,
-          false),
-    (  EqPrec < FPrec ->
+    nonvar(Value),
+    \+ integer(Value),
+    functor(Value, F, Arity),
+    current_op(FPrec, _, F),
+    current_op(EqPrec, EqSpec, Op),
+    (  Arity =:= 0 ->
+       true
+    ;  EqPrec < FPrec ->
        true
     ;  FPrec > 0, F == Value, graphic_token_char(F) ->
        true
@@ -228,7 +230,7 @@ write_goal(G, VarList, MaxDepth) :-
        ),
        write(Var),
        write(' = '),
-       (  needs_bracketing(Value, (=)) ->
+       (  needs_bracketing(Value, =) ->
           write('('),
           write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]),
           write(')')
@@ -247,7 +249,7 @@ write_last_goal(G, VarList, MaxDepth) :-
        ),
        write(Var),
        write(' = '),
-       (  needs_bracketing(Value, (=)) ->
+       (  needs_bracketing(Value, =) ->
           write('('),
           write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]),
           write(')')
@@ -271,8 +273,7 @@ write_eq(G, VarList, MaxDepth) :-
     write_last_goal(G, VarList, MaxDepth).
 
 graphic_token_char(C) :-
-    memberchk(C, ['#', '$', '&', '*', '+', '-', '.', ('/'), ':',
-                  '<', '=', '>', '?', '@', '^', '~', ('\\')]).
+    memberchk(C, [#, $, &, *, +, -, ., /, :, <, =, >, ?, @, ^, ~, \\]).
 
 list_last_item([C], C) :- !.
 list_last_item([_|Cs], D) :-