This question is directly related to first order logic creating terms for arithmetic expressions using prolog. After implementing the logic as per the link I have issues with the formatting of the ourput for printauth/1
. It currently results as 8-2+4* -3
, how is it possible to get something like ((8-2)+(4* -3))
(notice its not the same as +(-(8,2),*(4,-3)))
.
I have been trying to using various options (\k,\q) in format/2
predicate but nothing works. even I tried write_canonical
and other write predicates, still no success.
printterm(Term) :- arithmetic_expression(Term, Expr), format("(~q)\n", [Expr]).
%write_canonical(Expr).
%write_term(Expr, [ignore_ops(true)]).
%format("(~q)\n", [Expr]) .
current output:
?- printterm(plus((minus(8,2)),(times(4,3)))).
(8-2+4*3)
true .
expected output:
?- printterm(plus((minus(8,2)),(times(4,3)))).
((8-2)+(4*3))
true .
Is it possible to achieve this?