[m-rev.] for review: string__join_list

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Jul 31 16:31:44 AEST 2001


On 30-Jul-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > +	len = 0;
> > +	add_sep = FALSE;
> >  	while (!MR_list_is_empty(list)) {
> > -		len += sep_len + strlen((MR_String) MR_list_head(list));
> > -		list = MR_list_tail(list);
> > +		if (add_sep) {
> > +			len += sep_len;
> >  	}
> >  
> > -		/* Allocate enough word aligned memory for the string */
> > -	if (len <= 0) {
> > -		len = 0;
> > +		len += strlen((MR_String) MR_list_head(list));
> > +		list = MR_list_tail(list);
> > +		add_sep = FALSE;
> 
> Shouldn't that be `add_sep = TRUE'?

Yes. That's what you get for trying to program after four hours of sleep.
Damn all 10am lectures :-(

Here is the test case.

library/tests/hard_coded/join_list.{m,exp}:
	A new test case to exercise string__join_list.

library/tests/hard_coded/Mmakefile:
	Enable the new test.

Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.123
diff -u -b -r1.123 Mmakefile
--- tests/hard_coded/Mmakefile	2001/07/06 17:12:04	1.123
+++ tests/hard_coded/Mmakefile	2001/07/30 05:17:25
@@ -72,6 +72,7 @@
 	integer_test \
 	intermod_c_code \
 	intermod_multimode_main \
+	join_list \
 	merge_and_remove_dups \
 	minint_bug \
 	mode_choice \
Index: tests/hard_coded/join_list.exp
===================================================================
RCS file: join_list.exp
diff -N join_list.exp
--- /dev/null	Fri Dec  1 02:25:58 2000
+++ join_list.exp	Mon Jul 30 15:13:53 2001
@@ -0,0 +1,36 @@
+
+
+
+
+a, b
+a b
+a x b
+ab
+a, b, c
+a b c
+a x b x c
+abc
+a, , c
+a  c
+a x  x c
+ac
+abc, def, ghi
+abc def ghi
+abc x def x ghi
+abcdefghi
+the, quick, brown, fox, jumped, over, the, lazy, dog
+the quick brown fox jumped over the lazy dog
+the x quick x brown x fox x jumped x over x the x lazy x dog
+thequickbrownfoxjumpedoverthelazydog
+this, is, a, test, to, check, the correctness,  of the, join_list , predicate
+
+this is a test to check the correctness  of the join_list  predicate
+
+this x is x a x test x to x check x the correctness x  of the x join_list  x predicate
+
+thisisatesttocheckthe correctness of thejoin_list predicate
+
+ , 	,  	 , x
+  	  	  x
+  x 	 x  	  x x
+ 	 	 x
Index: tests/hard_coded/join_list.m
===================================================================
RCS file: join_list.m
diff -N join_list.m
--- /dev/null	Fri Dec  1 02:25:58 2000
+++ join_list.m	Mon Jul 30 15:13:50 2001
@@ -0,0 +1,39 @@
+% This is a test to check the correctness of the string__join_list predicate.
+
+:- module join_list.
+
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+:- import_module list, string.
+
+main -->
+	test_join_list([]),
+	test_join_list(["a", "b"]),
+	test_join_list(["a", "b", "c"]),
+	test_join_list(["a", "", "c"]),
+	test_join_list(["abc", "def", "ghi"]),
+	test_join_list(["the", "quick", "brown", "fox", "jumped", "over",
+		"the", "lazy", "dog"]),
+	test_join_list(["this", "is", "a", "test", "to", "check",
+		"the correctness", " of the", "join_list ", "predicate\n"]),
+	test_join_list([" ", "\t", " \t ", "x"]).
+
+:- pred test_join_list(list(string)::in, io__state::di, io__state::uo) is det.
+
+test_join_list(Pieces) -->
+	{ Joined1 = string__join_list(", ", Pieces) },
+	io__write_string(Joined1),
+	io__write_string("\n"),
+	{ Joined2 = string__join_list(" ", Pieces) },
+	io__write_string(Joined2),
+	io__write_string("\n"),
+	{ Joined3 = string__join_list(" x ", Pieces) },
+	io__write_string(Joined3),
+	io__write_string("\n"),
+	{ Joined4 = string__join_list("", Pieces) },
+	io__write_string(Joined4),
+	io__write_string("\n").
--------------------------------------------------------------------------
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