[m-rev.] Fix a bug in string.string

Ralph Becket rafe at cs.mu.OZ.AU
Wed Aug 3 16:58:50 AEST 2005


Estimated hours taken: 1
Branches: main, release

Fix a bug in string.string reported by Peter Ross.

library/string.m:
	Bugfix: previously string.value_to_revstrings was not calling
	univ_value on arguments of functors that are handled specially.  This
	caused spurious "univ_cons" functors to appear in the string
	representations of some terms.

test/hard_coded/string_string.exp:
test/hard_coded/string_string.m:
	Extended the test case for string.string to cover Peter's example.

Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.233
diff -u -r1.233 string.m
--- library/string.m	16 Jun 2005 04:08:05 -0000	1.233
+++ library/string.m	3 Aug 2005 05:28:26 -0000
@@ -4246,8 +4246,8 @@
 
 
 
-string__string(NonCanon, OpsTable, Univ, String) :-
-	value_to_revstrings(NonCanon, OpsTable, Univ, [], RevStrings),
+string__string(NonCanon, OpsTable, X, String) :-
+	value_to_revstrings(NonCanon, OpsTable, X, [], RevStrings),
 	String = string__append_list(list__reverse(RevStrings)).
 
 
@@ -4261,9 +4261,9 @@
 :- mode value_to_revstrings(in, in, in, in, out)
 	is cc_multi.
 
-value_to_revstrings(NonCanon, OpsTable, Univ, !Rs) :-
+value_to_revstrings(NonCanon, OpsTable, X, !Rs) :-
 	Priority = ops__max_priority(OpsTable) + 1,
-	value_to_revstrings(NonCanon, OpsTable, Priority, Univ, !Rs).
+	value_to_revstrings(NonCanon, OpsTable, Priority, X, !Rs).
 
 
 
@@ -4415,7 +4415,7 @@
 		add_revstring(" ", !Rs),
 		adjust_priority(OpPriority, OpAssoc, NewPriority),
 		value_to_revstrings(NonCanon, OpsTable, NewPriority,
-			PrefixArg, !Rs),
+			univ_value(PrefixArg), !Rs),
 		maybe_add_revstring(")", Priority, OpPriority, !Rs)
 	;
 		Args = [PostfixArg],
@@ -4425,7 +4425,7 @@
 		maybe_add_revstring("(", Priority, OpPriority, !Rs),
 		adjust_priority(OpPriority, OpAssoc, NewPriority),
 		value_to_revstrings(NonCanon, OpsTable, NewPriority,
-			PostfixArg, !Rs),
+			univ_value(PostfixArg), !Rs),
 		add_revstring(" ", !Rs),
 		add_revstring(term_io__quoted_atom(Functor), !Rs),
 		maybe_add_revstring(")", Priority, OpPriority, !Rs)
@@ -4436,7 +4436,8 @@
 	->
 		maybe_add_revstring("(", Priority, OpPriority, !Rs),
 		adjust_priority(OpPriority, LeftAssoc, LeftPriority),
-		value_to_revstrings(NonCanon, OpsTable, LeftPriority, Arg1, !Rs),
+		value_to_revstrings(NonCanon, OpsTable, LeftPriority,
+			univ_value(Arg1), !Rs),
 		( Functor = "," ->
 			add_revstring(", ", !Rs)
 		;
@@ -4446,7 +4447,7 @@
 		),
 		adjust_priority(OpPriority, RightAssoc, RightPriority),
 		value_to_revstrings(NonCanon, OpsTable, RightPriority,
-			Arg2, !Rs),
+			univ_value(Arg2), !Rs),
 		maybe_add_revstring(")", Priority, OpPriority, !Rs)
 	;
 		Args = [Arg1, Arg2],
@@ -4458,11 +4459,11 @@
 		add_revstring(" ", !Rs),
 		adjust_priority(OpPriority, FirstAssoc, FirstPriority),
 		value_to_revstrings(NonCanon, OpsTable, FirstPriority,
-			Arg1, !Rs),
+			univ_value(Arg1), !Rs),
 		add_revstring(" ", !Rs),
 		adjust_priority(OpPriority, SecondAssoc, SecondPriority),
 		value_to_revstrings(NonCanon, OpsTable, SecondPriority,
-			Arg2, !Rs),
+			univ_value(Arg2), !Rs),
 		maybe_add_revstring(")", Priority, OpPriority, !Rs)
 	;
 		(
Index: tests/hard_coded/string_string.exp
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/string_string.exp,v
retrieving revision 1.2
diff -u -r1.2 string_string.exp
--- tests/hard_coded/string_string.exp	20 Dec 2004 14:22:54 -0000	1.2
+++ tests/hard_coded/string_string.exp	3 Aug 2005 06:45:25 -0000
@@ -1,3 +1,4 @@
 leaf
 branch(leaf, leaf)
 [1, 2, 3]
+1.23400000000000 - 5
Index: tests/hard_coded/string_string.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/string_string.m,v
retrieving revision 1.2
diff -u -r1.2 string_string.m
--- tests/hard_coded/string_string.m	20 Dec 2004 14:22:54 -0000	1.2
+++ tests/hard_coded/string_string.m	3 Aug 2005 06:44:45 -0000
@@ -21,7 +21,7 @@
 
 :- implementation.
 
-:- import_module string, list.
+:- import_module string, list, std_util.
 
 :- type tree ---> leaf; branch(tree, tree).
 
@@ -30,7 +30,8 @@
 main(!IO) :-
     io.write_string(string.string(leaf) ++ "\n", !IO),
     io.write_string(string.string(branch(leaf, leaf)) ++ "\n", !IO),
-    io.write_string(string.string([1,2,3]) ++ "\n", !IO).
+    io.write_string(string.string([1,2,3]) ++ "\n", !IO),
+    io.write_string(string.string(1.234 - 5) ++ "\n", !IO).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list