]> Repositorios git - scryer-prolog.git/commitdiff
add conditional bracketing to equations printed by toplevel
authorMark Thom <[email protected]>
Thu, 21 Nov 2019 20:26:00 +0000 (16:26 -0400)
committerMark Thom <[email protected]>
Thu, 21 Nov 2019 20:26:00 +0000 (16:26 -0400)
src/prolog/machine/machine_state.rs
src/prolog/toplevel.pl

index edb5f419183bbc075d971c1aecf47c46ccb5026f..c632e05963e0e999731b764292344d4aac3b4dcf 100644 (file)
@@ -461,7 +461,7 @@ pub(crate) trait CallPolicy: Any {
         let b = machine_st.b - 1;
         let n = machine_st.or_stack[b].num_args();
 
-        for i in 1..n + 1 {
+        for i in 1 .. n + 1 {
             machine_st.registers[i] = machine_st.or_stack[b][i].clone();
         }
 
index f9eba5dd5997175abc29b231a70531cc5eafd7a8..e3c8a60581f0d94497977a898b9ed5e0420221ef 100644 (file)
     ;  write('false.'), nl
     ).
 
+'$needs_bracketing'(Value, Op) :-
+    catch((functor(Value, F, _),
+          current_op(EqPrec, EqSpec, Op),
+          current_op(FPrec, _, F)),
+         _,
+         false),
+    (  EqPrec < FPrec -> true
+    ;  EqPrec == FPrec,
+       memberchk(EqSpec, [fx,xfx,yfx])
+    ).
+
 '$write_goal'(G, VarList) :-
     (  G = (Var = Value) ->
        write(Var),
        write(' = '),
-       write_term(Value, [quoted(true), variable_names(VarList)])
+       (  '$needs_bracketing'(Value, (=)) ->
+         write('('),
+         write_term(Value, [quoted(true), variable_names(VarList)]),
+         write(')')
+       ;  write_term(Value, [quoted(true), variable_names(VarList)])
+       )
     ;  G == [] ->
        write('true')
     ;  write_term(G, [quoted(true), variable_names(VarList)])