diff: io.m: io__write parentheses bug fix

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Jan 28 22:34:12 AEDT 1999


Estimated hours taken: 0.75

library/io.m:
	Fix a bug reported by Tom Conway:
	io__write was not properly parenthesizing term arguments.

Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.172
diff -u -r1.172 io.m
--- io.m	1998/11/19 06:10:59	1.172
+++ io.m	1999/01/28 03:06:59
@@ -1896,7 +1896,7 @@
 		{ Args = [ListHead, ListTail] }
 	->
 		io__write_char('['),
-		io__write_univ(ListHead),
+		io__write_arg(ListHead),
 		io__write_list_tail(ListTail),
 		io__write_char(']')
 	;
@@ -1983,7 +1983,7 @@
 			{ Args = [X|Xs] }
 		->
 			io__write_char('('),
-			io__write_univ(X),
+			io__write_arg(X),
 			io__write_term_args(Xs),
 			io__write_char(')')
 		;
@@ -2016,7 +2016,7 @@
 		{ deconstruct(Term, ".", _Arity, [ListHead, ListTail]) }
 	->
 		io__write_string(", "),
-		io__write_univ(ListHead),
+		io__write_arg(ListHead),
 		io__write_list_tail(ListTail)
 	;
 		{ deconstruct(Term, "[]", _Arity, []) }
@@ -2034,8 +2034,30 @@
 io__write_term_args([]) --> [].
 io__write_term_args([X|Xs]) -->
 	io__write_string(", "),
-	io__write_univ(X),
+	io__write_arg(X),
 	io__write_term_args(Xs).
+
+:- pred io__write_arg(univ, io__state, io__state).
+:- mode io__write_arg(in, di, uo) is det.
+
+io__write_arg(X) -->
+	arg_priority(ArgPriority),
+	io__write_univ(X, ArgPriority).
+
+:- pred arg_priority(int, io__state, io__state).
+:- mode arg_priority(out, di, uo) is det.
+/*
+arg_priority(ArgPriority) -->
+	io__get_op_table(OpTable),
+	{ ops__lookup_infix_op(OpTable, ",", Priority, _, _) ->
+		ArgPriority = Priority }
+	;
+		error("arg_priority: can't find the priority of `,'")
+	}.
+*/
+% We could implement this as above, but it's more efficient to just
+% hard-code it.
+arg_priority(1000) --> [].
 
 %-----------------------------------------------------------------------------%

-- 
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