[fjh at cs.mu.OZ.AU: Re: [m-rev.] For review: updates to string.m]

Ralph Becket rafe at cs.mu.OZ.AU
Mon Oct 28 17:05:41 AEDT 2002


Fergus Henderson, Monday, 28 October 2002:
> On 28-Oct-2002, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> > library/string.m:
> > 	Changed the behaviour of string__foldr_substring to be "safe"
> > 	in the sense that it is equivalent to calling
> > 	    foldr(Closure, substring(String, Start, Count), Acc0, Acc)
> > 	rather than
> > 	    foldr(Closure, unsafe_substring(String, Start, Count), Acc0, Acc).
> 
> That looks good, thanks. 
> 
> It would be nice to also add a test case for this.

Estimated hours taken: 0.5
Branches: main

tests/general/string_foldr_substring.m:
tests/general/string_foldr_substring.exp:
	Added.

tests/general/Mmakefile:
	Include string_foldr_substring test.

Index: string_foldr_substring.m
===================================================================
RCS file: string_foldr_substring.m
diff -N string_foldr_substring.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ string_foldr_substring.m	28 Oct 2002 05:59:55 -0000
@@ -0,0 +1,53 @@
+%-----------------------------------------------------------------------------%
+% string_foldr_substring.m
+% Ralph Becket <rafe at cs.mu.oz.au>
+% Mon Oct 28 16:32:19 EST 2002
+% vim: ft=mercury ff=unix ts=4 sw=4 et wm=0 tw=0
+%
+%-----------------------------------------------------------------------------%
+
+:- module string_foldr_substring.
+
+:- interface.
+
+:- import_module io.
+
+
+
+:- pred main(io::di, io::uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module string, char, list, int.
+
+%-----------------------------------------------------------------------------%
+
+main(!IO) :-
+    io__write_strings([
+            "sub(\"Hello, World!\",  0,  5) = \"",
+               sub("Hello, World!",  0,  5),
+        "\"\nsub(\"Hello, World!\",  0, 50) = \"",
+               sub("Hello, World!",  0, 50),
+        "\"\nsub(\"Hello, World!\",  0, -5) = \"",
+               sub("Hello, World!",  0, -5),
+        "\"\nsub(\"Hello, World!\", -5, 12) = \"",
+               sub("Hello, World!", -5, 12),
+        "\"\nsub(\"Hello, World!\", -5, 50) = \"",
+               sub("Hello, World!", -5, 50),
+        "\"\nsub(\"Hello, World!\",  7,  0) = \"",
+               sub("Hello, World!",  7,  0),
+        "\"\nsub(\"Hello, World!\", 50, 10) = \"",
+               sub("Hello, World!", 50, 10),
+        "\"\n"
+    ], !IO).
+
+:- func sub(string, int, int) = string.
+
+sub(S, I, N) =
+    from_char_list(foldr_substring(func(X, Xs) = [X | Xs], S, I, N, [])).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: string_foldr_substring.exp
===================================================================
RCS file: string_foldr_substring.exp
diff -N string_foldr_substring.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ string_foldr_substring.exp	28 Oct 2002 05:58:26 -0000
@@ -0,0 +1,7 @@
+sub("Hello, World!",  0,  5) = "Hello"
+sub("Hello, World!",  0, 50) = "Hello, World!"
+sub("Hello, World!",  0, -5) = ""
+sub("Hello, World!", -5, 12) = "Hello, World"
+sub("Hello, World!", -5, 50) = "Hello, World!"
+sub("Hello, World!",  7,  0) = ""
+sub("Hello, World!", 50, 10) = ""
Index: Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/general/Mmakefile,v
retrieving revision 1.41
diff -u -r1.41 Mmakefile
--- Mmakefile	17 Aug 2002 13:52:06 -0000	1.41
+++ Mmakefile	28 Oct 2002 06:03:18 -0000
@@ -53,6 +53,7 @@
 		set_test \
 		state_vars_tests \
 		state_vars_typeclasses \
+		string_foldr_substring \
 		string_format_test \
 		string_format_test_2 \
 		string_format_test_3 \
--------------------------------------------------------------------------
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