[m-rev.] diff: some additions for the library and more cleanups

Julien Fischer juliensf at cs.mu.OZ.AU
Sat Feb 26 22:59:17 AEDT 2005


Estimated hours taken: 1
Branches: main, release

Add some synonyms for various functions in the string module
and make some more general cleanups to parts of the standard library.

library/array.m:
	s/applys/applies/

library/list.m:
	Position descriptive comments according to our coding
	standard.

	Fix a cut and paste error.  list.foldl6 has six accumulators
	not five.

library/parser.m:
library/pqueue.m:
library/set_bbbtree.m:
library/set_ctree234.m:
library/sparse_bitset.m:
	Fix minor formatting problems and spelling mistakes.

library/string.m:
	Add functions string.from_int/1, string.from_char/1
	and string.from_float/1 as synonyms for string.int_to_string/1
	etc.

Julien.

(NOTE: the following diff is against the release branch)

Index: array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.136.2.1
diff -u -r1.136.2.1 array.m
--- array.m	2 Feb 2005 04:44:32 -0000	1.136.2.1
+++ array.m	26 Feb 2005 07:11:51 -0000
@@ -336,7 +336,7 @@
 :- mode array__bsearch(array_ui, in, in(comparison_func)) = out is det.
 :- mode array__bsearch(in, in, in(comparison_func)) = out is det.

-	% array__map(Closure, OldArray, NewArray) applys `Closure' to
+	% array__map(Closure, OldArray, NewArray) applies `Closure' to
 	% each of the elements of `OldArray' to create `NewArray'.
 	%
 :- pred array__map(pred(T1, T2), array(T1), array(T2)).
Index: list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.129.2.1
diff -u -r1.129.2.1 list.m
--- list.m	2 Feb 2005 04:44:37 -0000	1.129.2.1
+++ list.m	26 Feb 2005 09:47:57 -0000
@@ -487,6 +487,7 @@
 	% element of List (working left-to-right) and an accumulator
 	% (with the initial value of Start), and returns the final
 	% value in End.
+	%
 :- pred list__foldl(pred(L, A, A), list(L), A, A).
 :- mode list__foldl(pred(in, di, uo) is det, in, di, uo) is det.
 :- mode list__foldl(pred(in, in, out) is det, in, in, out) is det.
@@ -501,6 +502,7 @@
 	% element of List (working right-to-left) and an accumulator
 	% (with the initial value of Start), and returns the final
 	% value in End.
+	%
 :- pred list__foldr(pred(L, A, A), list(L), A, A).
 :- mode list__foldr(pred(in, di, uo) is det, in, di, uo) is det.
 :- mode list__foldr(pred(in, in, out) is det, in, in, out) is det.
@@ -515,6 +517,7 @@
 	% Does the same job as list__foldl, but with two accumulators.
 	% (Although no more expressive than list__foldl, this is often
 	% a more convenient format, and a little more efficient).
+	%
 :- pred list__foldl2(pred(L, A, A, Z, Z), list(L), A, A, Z, Z).
 :- mode list__foldl2(pred(in, in, out, in, out) is det,
 	in, in, out, in, out) is det.
@@ -541,6 +544,7 @@
 	% Does the same job as list__foldl, but with three accumulators.
 	% (Although no more expressive than list__foldl, this is often
 	% a more convenient format, and a little more efficient).
+	%
 :- pred list__foldl3(pred(L, A, A, B, B, C, C), list(L),
 	A, A, B, B, C, C).
 :- mode list__foldl3(pred(in, in, out, in, out, in, out) is det,
@@ -560,6 +564,7 @@
 	% Does the same job as list__foldl, but with four accumulators.
 	% (Although no more expressive than list__foldl, this is often
 	% a more convenient format, and a little more efficient).
+	%
 :- pred list__foldl4(pred(L, A, A, B, B, C, C, D, D), list(L),
 	A, A, B, B, C, C, D, D).
 :- mode list__foldl4(pred(in, in, out, in, out, in, out, in, out) is det,
@@ -579,6 +584,7 @@
 	% Does the same job as list__foldl, but with five accumulators.
 	% (Although no more expressive than list__foldl, this is often
 	% a more convenient format, and a little more efficient).
+	%
 :- pred list__foldl5(pred(L, A, A, B, B, C, C, D, D, E, E), list(L),
 	A, A, B, B, C, C, D, D, E, E).
 :- mode list__foldl5(pred(in, in, out, in, out, in, out, in, out, in, out)
@@ -601,9 +607,10 @@
 	in, in, out, in, out, in, out, in, out, di, uo) is cc_multi.

 	% list__foldl6(Pred, List, !Acc1, !Acc2, !Acc3, !Acc4, !Acc5, !Acc6)
-	% Does the same job as list__foldl, but with five accumulators.
+	% Does the same job as list__foldl, but with six accumulators.
 	% (Although no more expressive than list__foldl, this is often
 	% a more convenient format, and a little more efficient).
+	%
 :- pred list__foldl6(pred(L, A, A, B, B, C, C, D, D, E, E, F, F), list(L),
 	A, A, B, B, C, C, D, D, E, E, F, F).
 :- mode list__foldl6(pred(in, in, out, in, out, in, out, in, out, in, out,
@@ -630,6 +637,7 @@
 	% each element of InList (working left-to-right) to transform
 	% InList into OutList.  The final value of the accumulator is
 	% returned in End.
+	%
 :- pred list__map_foldl(pred(L, M, A, A), list(L), list(M), A, A).
 :- mode list__map_foldl(pred(in, out, di, uo) is det, in, out, di, uo)
 	is det.
@@ -645,6 +653,7 @@
 	is nondet.

 	% Same as list__map_foldl, but with two mapped outputs.
+	%
 :- pred list__map2_foldl(pred(L, M, N, A, A), list(L), list(M), list(N),
 	A, A).
 :- mode list__map2_foldl(pred(in, out, out, di, uo) is det, in, out, out,
@@ -661,6 +670,7 @@
 	in, out) is nondet.

 	% Same as list__map_foldl, but with two accumulators.
+	%
 :- pred list__map_foldl2(pred(L, M, A, A, B, B), list(L), list(M), A, A, B, B).
 :- mode list__map_foldl2(pred(in, out, in, out, di, uo) is det,
 	in, out, in, out, di, uo) is det.
@@ -676,6 +686,7 @@
 	in, out, in, out, in, out) is nondet.

 	% Same as list__map_foldl, but with three accumulators.
+	%
 :- pred list__map_foldl3(pred(L, M, A, A, B, B, C, C), list(L), list(M),
 	A, A, B, B, C, C).
 :- mode list__map_foldl3(pred(in, out, in, out, in, out, di, uo) is det,
@@ -692,6 +703,7 @@
 	in, out, in, out, in, out, in, out) is nondet.

 	% Same as list__map_foldl, but with four accumulators.
+	%
 :- pred list__map_foldl4(pred(L, M, A, A, B, B, C, C, D, D), list(L), list(M),
 	A, A, B, B, C, C, D, D).
 :- mode list__map_foldl4(pred(in, out, in, out, in, out, in, out, di, uo)
@@ -714,6 +726,7 @@
 	in, out, in, out, in, out, in, out, in, out) is nondet.

 	% Same as list__map_foldl, but with five accumulators.
+	%
 :- pred list__map_foldl5(pred(L, M, A, A, B, B, C, C, D, D, E, E),
 	list(L), list(M), A, A, B, B, C, C, D, D, E, E).
 :- mode list__map_foldl5(pred(in, out, in, out, in, out, in, out, in, out,
@@ -736,6 +749,7 @@
 	in, out, in, out, in, out, in, out, in, out, in, out) is nondet.

 	% Same as list__map_foldl, but with six accumulators.
+	%
 :- pred list__map_foldl6(pred(L, M, A, A, B, B, C, C, D, D, E, E, F, F),
 	list(L), list(M), A, A, B, B, C, C, D, D, E, E, F, F).
 :- mode list__map_foldl6(pred(in, out, in, out, in, out, in, out, in, out,
@@ -764,18 +778,21 @@
 	% list__all_true(Pred, List) takes a closure with one input argument.
 	% If Pred succeeds for every member of List, all_true succeeds.
 	% If Pred fails for any member of List, all_true fails.
+	%
 :- pred list__all_true(pred(X)::in(pred(in) is semidet), list(X)::in)
 	is semidet.

 	% list__all_false(Pred, List) takes a closure with one input argument.
 	% If Pred fails for every member of List, all_false succeeds.
 	% If Pred succeeds for any member of List, all_false fails.
+	%
 :- pred list__all_false(pred(X)::in(pred(in) is semidet), list(X)::in)
 	is semidet.

 	% list__filter(Pred, List, TrueList) takes a closure with one
 	% input argument and for each member of List `X', calls the closure.
 	% Iff call(Pred, X) is true, then X is included in TrueList.
+	%
 :- pred list__filter(pred(X)::in(pred(in) is semidet), list(X)::in,
 	list(X)::out) is det.
 :- func list__filter(pred(X)::in(pred(in) is semidet), list(X)::in)
@@ -785,6 +802,7 @@
 	% input argument and for each member of List `X', calls the closure.
 	% Iff call(Pred, X) is true, then X is included in TrueList.
 	% Iff call(Pred, X) is false, then X is included in FalseList.
+	%
 :- pred list__filter(pred(X)::in(pred(in) is semidet), list(X)::in,
 	list(X)::out, list(X)::out) is det.

@@ -792,6 +810,7 @@
 	% with one input argument and one output argument. It is called
 	% with each element of List. If a call succeeds, then the output is
 	% included in TrueList.
+	%
 :- pred list__filter_map(pred(X, Y)::in(pred(in, out) is semidet),
 	list(X)::in, list(Y)::out) is det.

@@ -803,6 +822,7 @@
 	% It is called with each element of List. If a call succeeds,
 	% then the output is included in TrueList; otherwise, the failing
 	% input is included in FalseList.
+	%
 :- pred list__filter_map(pred(X, Y)::in(pred(in, out) is semidet),
 	list(X)::in, list(Y)::out, list(X)::out) is det.

@@ -812,6 +832,7 @@
 	% the call succeeds are placed in UptoList and the first element for
 	% which the call fails, and all the remaining elements of List are
 	% placed in AfterList.
+	%
 :- pred list__takewhile(pred(T)::in(pred(in) is semidet), list(T)::in,
 	list(T)::out, list(T)::out) is det.

@@ -823,6 +844,7 @@
 	% term Compare, and the elements that are equivalent in this ordering
 	% appear in the same sequence in Sorted as they do in Unsorted
 	% (that is, the sort is stable).
+	%
 :- pred list__sort(comparison_pred(X)::in(comparison_pred), list(X)::in,
 	list(X)::out) is det.
 :- func list__sort(comparison_func(X), list(X)) = list(X).
@@ -833,6 +855,7 @@
 	% predicate term Compare, except that if two elements in Unsorted
 	% are equivalent with respect to this ordering only the one which
 	% occurs first will be in Sorted.
+	%
 :- pred list__sort_and_remove_dups(comparison_pred(X)::in(comparison_pred),
 	list(X)::in, list(X)::out) is det.

@@ -840,6 +863,7 @@
 	% of replacing every sequence of elements in L0 which are equivalent
 	% with respect to the ordering, with the first occurrence in L0 of
 	% such an element.
+	%
 :- pred list__remove_adjacent_dups(comparison_pred(X)::in(comparison_pred),
 	list(X)::in, list(X)::out) is det.

@@ -850,6 +874,7 @@
 	% if they come from the same list then they appear in the same
 	% sequence in Sorted as they do in that list, otherwise the elements
 	% from As appear before the elements from Bs.
+	%
 :- pred list__merge(comparison_pred(X)::in(comparison_pred),
 	list(X)::in, list(X)::in, list(X)::out) is det.

@@ -862,6 +887,7 @@
 	% contains no duplicates.  If an element from As is duplicated in
 	% Bs (that is, they are equivalent in the ordering), then the element
 	% from As is the one that appears in Sorted.
+	%
 :- pred list__merge_and_remove_dups(comparison_pred(X)::in(comparison_pred),
 	list(X)::in, list(X)::in, list(X)::out) is det.

Index: parser.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/parser.m,v
retrieving revision 1.44.2.1
diff -u -r1.44.2.1 parser.m
--- parser.m	2 Feb 2005 04:44:40 -0000	1.44.2.1
+++ parser.m	26 Feb 2005 10:23:13 -0000
@@ -124,6 +124,7 @@
 	token_list::in, read_term(T)::out) is det <= op_table(Ops).

 %-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- implementation.

Index: pqueue.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/pqueue.m,v
retrieving revision 1.17
diff -u -r1.17 pqueue.m
--- pqueue.m	24 Jan 2005 23:16:38 -0000	1.17
+++ pqueue.m	26 Feb 2005 09:37:01 -0000
@@ -26,38 +26,37 @@

 :- import_module assoc_list.

-:- type pqueue(_K, _V).
+:- type pqueue(K, V).

 	% Create an empty priority queue
 	%
-:- pred pqueue__init(pqueue(_K, _V)::out) is det.
-:- func pqueue__init = pqueue(_K, _V).
+:- func pqueue__init = pqueue(K, V).
+:- pred pqueue__init(pqueue(K, V)::out) is det.

 	% Insert a value V with key K into a priority queue
 	% and return the new priority queue.
 	%
+:- func pqueue__insert(pqueue(K, V), K, V) = pqueue(K, V).
 :- pred pqueue__insert(pqueue(K, V)::in, K::in, V::in, pqueue(K, V)::out)
 	is det.
-:- func pqueue__insert(pqueue(K, V), K, V) = pqueue(K, V).

 	% Remove the smallest item from the priority queue.
 	%
 :- pred pqueue__remove(pqueue(K, V)::in, K::out, V::out, pqueue(K, V)::out)
 	is semidet.

-	% Extract all the items from a priority queue by
-	% repeated removal, and place them in an association
-	% list.
+	% Extract all the items from a priority queue by repeated
+	% removal, and place them in an association list.
 	%
-:- pred pqueue__to_assoc_list(pqueue(K, V)::in, assoc_list(K, V)::out) is det.
 :- func pqueue__to_assoc_list(pqueue(K, V)) = assoc_list(K, V).
+:- pred pqueue__to_assoc_list(pqueue(K, V)::in, assoc_list(K, V)::out) is det.

 	% Insert all the key-value pairs in an association list
 	% into a priority queue.
 	%
+:- func pqueue__assoc_list_to_pqueue(assoc_list(K, V)) = pqueue(K, V).
 :- pred pqueue__assoc_list_to_pqueue(assoc_list(K, V)::in, pqueue(K, V)::out)
 	is det.
-:- func pqueue__assoc_list_to_pqueue(assoc_list(K, V)) = pqueue(K, V).

 	% A synonym for pqueue.assoc_list_to_pqueue/1.
 	%
@@ -173,3 +172,7 @@

 pqueue__assoc_list_to_pqueue(AL) = PQ2 :-
 	pqueue__assoc_list_to_pqueue(AL, PQ2).
+
+%---------------------------------------------------------------------------%
+:- end_module pqueue.
+%---------------------------------------------------------------------------%
Index: set_bbbtree.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/set_bbbtree.m,v
retrieving revision 1.24
diff -u -r1.24 set_bbbtree.m
--- set_bbbtree.m	27 Jan 2005 03:59:27 -0000	1.24
+++ set_bbbtree.m	26 Feb 2005 11:24:03 -0000
@@ -775,10 +775,10 @@
 %------------------------------------------------------------------------------%

 % `set_bbbtree__power_intersect' is an accumulator based algorithm. Initially
-% the accumulator is seeded with the tree at the root. Then the tree is travesed
-% inorder and each tree at each node is respectively intersected with the
-% accumulator. The aim of the algorithm is to rapidly reduce the size of the
-% accumulator, possibly of the empty set in which case the call immediately
+% the accumulator is seeded with the tree at the root. Then the tree is
+% traversed inorder and each tree at each node is respectively intersected with
+% the accumulator. The aim of the algorithm is to rapidly reduce the size of
+% the accumulator, possibly of the empty set in which case the call immediately
 % returns.

 set_bbbtree__power_intersect(Sets, Set) :-
@@ -1018,11 +1018,11 @@

 %------------------------------------------------------------------------------%

-% Given two trees concatenate them by removing the greates element from the left
-% subtree if it is larger than the right subtree by a factor of ratio, else
-% the smallest element from the right subtree, and make it the root along with
-% the two remaining trees as its subtrees. No rebalancing is performed on the
-% resultant tree. `set_bbbtree__concat3' is largely used for deletion of
+% Given two trees concatenate them by removing the greatest element from the
+% left subtree if it is larger than the right subtree by a factor of ratio,
+% else the smallest element from the right subtree, and make it the root along
+% with the two remaining trees as its subtrees. No rebalancing is performed on
+% the resultant tree. `set_bbbtree__concat3' is largely used for deletion of
 % elements. This predicate should not be confused with the predicate `concat3'
 % in the paper for that is `set_bbbtree__concat4'.

Index: set_ctree234.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/set_ctree234.m,v
retrieving revision 1.2
diff -u -r1.2 set_ctree234.m
--- set_ctree234.m	25 Jan 2005 02:21:27 -0000	1.2
+++ set_ctree234.m	26 Feb 2005 07:18:04 -0000
@@ -154,7 +154,7 @@

     % `set_ctree234__union_list(A, B)' is true iff `B' is the union of
     % all the sets in `A'
-
+    %
 :- pred set_ctree234__union_list(list(set_ctree234(T))::in,
     set_ctree234(T)::out) is det.
 :- func set_ctree234__union_list(list(set_ctree234(T))) = set_ctree234(T).
Index: sparse_bitset.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/sparse_bitset.m,v
retrieving revision 1.22
diff -u -r1.22 sparse_bitset.m
--- sparse_bitset.m	24 Jan 2005 23:16:39 -0000	1.22
+++ sparse_bitset.m	26 Feb 2005 09:41:16 -0000
@@ -47,10 +47,9 @@
 :- type sparse_bitset(T). % <= enum(T).

 	% Return an empty set.
+	%
 :- func init = sparse_bitset(T).
-
-:- pred init(sparse_bitset(T)).
-:- mode init(out) is det.
+:- pred init(sparse_bitset(T)::out) is det.

 :- pred empty(sparse_bitset(T)).
 :- mode empty(in) is semidet.
Index: string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.225.2.1
diff -u -r1.225.2.1 string.m
--- string.m	2 Feb 2005 04:44:41 -0000	1.225.2.1
+++ string.m	26 Feb 2005 07:24:19 -0000
@@ -4,8 +4,6 @@
 % Public License - see the file COPYING.LIB in the Mercury distribution.
 %---------------------------------------------------------------------------%

-:- module string.
-
 % Main authors: fjh, petdr.
 % Stability: medium to high.

@@ -18,6 +16,8 @@

 %-----------------------------------------------------------------------------%

+:- module string.
+
 :- interface.
 :- import_module list, char.
 :- import_module deconstruct.
@@ -112,6 +112,10 @@
 :- mode string__char_to_string(in, uo) is det.
 :- mode string__char_to_string(out, in) is semidet.

+	% A synonym for string.char_to_string/1.
+	%
+:- func string__from_char(char::in) = (string::uo) is det.
+
 	% Convert an integer to a string.
 	%
 :- func string__int_to_string(int) = string.
@@ -119,6 +123,10 @@
 :- pred string__int_to_string(int, string).
 :- mode string__int_to_string(in, uo) is det.

+	% A synonym for string.int_to_string/1.
+	%
+:- func string__from_int(int::in) = (string::uo) is det.
+
 	% string__int_to_base_string(Int, Base, String):
 	% Convert an integer to a string in a given Base (between 2 and 36).
 	%
@@ -140,6 +148,10 @@
 :- pred string__float_to_string(float, string).
 :- mode string__float_to_string(in, uo) is det.

+	% A synonym for string.float_to_string/1.
+	%
+:- func string__from_float(float::in) = (string::uo) is det.
+
 	% string__first_char(String, Char, Rest) is true iff Char is
 	% the first character of String, and Rest is the remainder.
 	%
@@ -889,9 +901,13 @@
 string__char_to_string(Char, String) :-
 	string__to_char_list(String, [Char]).

+string__from_char(Char) = string__char_to_string(Char).
+
 string__int_to_string(N, Str) :-
 	string__int_to_base_string(N, 10, Str).

+string__from_int(N) = string__int_to_string(N).
+
 string__int_to_base_string(N, Base, Str) :-
 	(
 		Base >= 2, Base =< 36
@@ -2865,6 +2881,8 @@
 ").

 %-----------------------------------------------------------------------------%
+
+string__from_float(Flt) = string__float_to_string(Flt).

 :- pragma foreign_proc("C",
 	string__float_to_string(Flt::in, Str::uo),

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