[m-rev.] for review: fix string.string/1 bug

Ian MacLarty maclarty at cs.mu.OZ.AU
Mon Dec 20 22:07:29 AEDT 2004


For review by anyone.

Estimated hours taken: 0.2
Branches: main

Make string.string/1 format lists properly.  Previously it used to 
put univ_cons/1 around each tail element.

library/string.m
	The arguments returned from deconstruct are univs, so make 
	list_tail_to_revstrings expect a univ and rename to
	univ_list_tail_to_revstrings.

tests/hard_coded/string_string.exp
tests/hard_coded/string_string.m
	Test conversion of lists to strings.

Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.222
diff -u -r1.222 string.m
--- library/string.m	5 Dec 2004 16:32:59 -0000	1.222
+++ library/string.m	20 Dec 2004 06:58:06 -0000
@@ -4156,7 +4156,8 @@
 	->
 		add_revstring("[", !Rs),
 		arg_to_revstrings(NonCanon, OpsTable, ListHead, !Rs),
-		list_tail_to_revstrings(NonCanon, OpsTable, ListTail, !Rs),
+		univ_list_tail_to_revstrings(NonCanon, OpsTable, ListTail, 
+			!Rs),
 		add_revstring("]", !Rs)
 	;
 		Functor = "[]",
@@ -4288,25 +4289,26 @@
 
 
 
-:- pred list_tail_to_revstrings(deconstruct__noncanon_handling,
-	ops__table, T, revstrings, revstrings).
-:- mode list_tail_to_revstrings(in(do_not_allow), in, in, in, out) is det.
-:- mode list_tail_to_revstrings(in(canonicalize), in, in, in, out) is det.
-:- mode list_tail_to_revstrings(in(include_details_cc), in, in, in, out)
+:- pred univ_list_tail_to_revstrings(deconstruct__noncanon_handling,
+	ops__table, univ, revstrings, revstrings).
+:- mode univ_list_tail_to_revstrings(in(do_not_allow), in, in, in, out) is det.
+:- mode univ_list_tail_to_revstrings(in(canonicalize), in, in, in, out) is det.
+:- mode univ_list_tail_to_revstrings(in(include_details_cc), in, in, in, out)
 	is cc_multi.
-:- mode list_tail_to_revstrings(in, in, in, in, out) is cc_multi.
+:- mode univ_list_tail_to_revstrings(in, in, in, in, out) is cc_multi.
 
-list_tail_to_revstrings(NonCanon, OpsTable, X, !Rs) :-
-	deconstruct__deconstruct(X, NonCanon, Functor, _Arity, Args),
+univ_list_tail_to_revstrings(NonCanon, OpsTable, Univ, !Rs) :-
+	deconstruct__deconstruct(univ_value(Univ), NonCanon, Functor, _Arity, 
+		Args),
 	( Functor = "[|]", Args = [ListHead, ListTail] ->
 		add_revstring(", ", !Rs),
 		arg_to_revstrings(NonCanon, OpsTable, ListHead, !Rs),
-		list_tail_to_revstrings(NonCanon, OpsTable, ListTail, !Rs)
+		univ_list_tail_to_revstrings(NonCanon, OpsTable, ListTail, !Rs)
 	; Functor = "[]", Args = [] ->
 		true
 	;
 		add_revstring(" | ", !Rs),
-		value_to_revstrings(NonCanon, OpsTable, X, !Rs)
+		value_to_revstrings(NonCanon, OpsTable, univ_value(Univ), !Rs)
 	).
 
 
Index: tests/hard_coded/string_string.exp
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/string_string.exp,v
retrieving revision 1.1
diff -u -r1.1 string_string.exp
--- tests/hard_coded/string_string.exp	5 Oct 2004 05:49:01 -0000	1.1
+++ tests/hard_coded/string_string.exp	20 Dec 2004 10:46:31 -0000
@@ -1,2 +1,3 @@
 leaf
 branch(leaf, leaf)
+[1, 2, 3]
Index: tests/hard_coded/string_string.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/string_string.m,v
retrieving revision 1.1
diff -u -r1.1 string_string.m
--- tests/hard_coded/string_string.m	5 Oct 2004 05:49:01 -0000	1.1
+++ tests/hard_coded/string_string.m	20 Dec 2004 10:45:44 -0000
@@ -21,7 +21,7 @@
 
 :- implementation.
 
-:- import_module string.
+:- import_module string, list.
 
 :- type tree ---> leaf; branch(tree, tree).
 
@@ -29,7 +29,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(branch(leaf, leaf)) ++ "\n", !IO),
+    io.write_string(string.string([1,2,3]) ++ "\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