term_io bug fix

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 11 15:30:18 AEDT 1998


Tom, the diff below should fix the term_io bug that you reported. 
I've checked that it compiles, but I haven't tested it.  Would you mind
testing it, adding a regression test and committing this change for me?

Estimated hours taken: 0.5

library/term_io.m:
	Fix a bug: term_io__write_term was not properly parenthesizing
	term arguments.

Index: library/term_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term_io.m,v
retrieving revision 1.54
diff -u -r1.54 term_io.m
--- term_io.m	1998/11/09 02:43:57	1.54
+++ term_io.m	1998/11/11 04:01:34
@@ -175,6 +175,14 @@
 	{ ops__max_priority(MaxPriority) },
 	term_io__write_term_3(Term, MaxPriority + 1, VarSet0, N0, VarSet, N).
 
+:- pred term_io__write_arg_term(term, varset, int, varset, int,
+				io__state, io__state).
+:- mode term_io__write_arg_term(in, in, in, out, out, di, uo) is det.
+
+term_io__write_arg_term(Term, VarSet0, N0, VarSet, N) -->
+	{ ArgPriority = 1000 },
+	term_io__write_term_3(Term, ArgPriority - 1, VarSet0, N0, VarSet, N).
+
 :- pred term_io__write_term_3(term, ops__priority, varset, int, varset, int,
 				io__state, io__state).
 :- mode term_io__write_term_3(in, in, in, in, out, out, di, uo) is det.
@@ -189,7 +197,7 @@
 		{ Args = [ListHead, ListTail] }
 	->
 		io__write_char('['),
-		term_io__write_term_2(ListHead, VarSet0, N0, VarSet1, N1),
+		term_io__write_arg_term(ListHead, VarSet0, N0, VarSet1, N1),
 		term_io__write_list_tail(ListTail, VarSet1, N1, VarSet, N),
 		io__write_char(']')
 	;
@@ -215,7 +223,7 @@
 	->
 		term_io__write_variable_2(Var, VarSet0, N0, VarSet1, N1),
 		io__write_char('('),
-		term_io__write_term_2(FirstArg, VarSet1, N1, VarSet2, N2),
+		term_io__write_arg_term(FirstArg, VarSet1, N1, VarSet2, N2),
 		term_io__write_term_args(OtherArgs, VarSet2, N2, VarSet, N),
 		io__write_char(')')
 	;
@@ -301,7 +309,7 @@
 			{ Args = [X|Xs] }
 		->
 			io__write_char('('),
-			term_io__write_term_2(X, VarSet0, N0, VarSet1, N1),
+			term_io__write_arg_term(X, VarSet0, N0, VarSet1, N1),
 			term_io__write_term_args(Xs, VarSet1, N1, VarSet, N),
 			io__write_char(')')
 		;
@@ -341,7 +349,7 @@
 		{ Term = term__functor(term__atom("."), [ListHead, ListTail], _) }
 	->
 		io__write_string(", "),
-		term_io__write_term_2(ListHead, VarSet0, N0, VarSet1, N1),
+		term_io__write_arg_term(ListHead, VarSet0, N0, VarSet1, N1),
 		term_io__write_list_tail(ListTail, VarSet1, N1, VarSet, N)
 	;
 		{ Term = term__functor(term__atom("[]"), [], _) }
@@ -363,7 +371,7 @@
 term_io__write_term_args([], VarSet, N, VarSet, N) --> [].
 term_io__write_term_args([X|Xs], VarSet0, N0, VarSet, N) -->
 	io__write_string(", "),
-	term_io__write_term_2(X, VarSet0, N0, VarSet1, N1),
+	term_io__write_arg_term(X, VarSet0, N0, VarSet1, N1),
 	term_io__write_term_args(Xs, VarSet1, N1, VarSet, N).
 
 %-----------------------------------------------------------------------------%

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"
PGP: finger fjh at 128.250.37.3        |     -- leaked Microsoft memo.



More information about the developers mailing list