add conditional bracketing to equations printed by toplevel

This commit is contained in:
Mark Thom
2019-11-21 16:26:00 -04:00
parent f82c6f3fed
commit b31b23e41c
2 changed files with 18 additions and 2 deletions

View 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();
}

View File

@@ -44,11 +44,27 @@
; 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)])