[m-rev.] For review: New predicates in assoc_list

Paul Bone pbone at csse.unimelb.edu.au
Wed Mar 17 17:32:00 AEDT 2010


For review by anyone.

Branches: main

Introduce new predicates in the assoc_list standard library module.  These
predicates complement the existing fuctions map_keys_only/3 map_values_only/3
and map_values.

library/assoc_list.m:
    As above.

NEWS:
    Announce this change.

    Rename old "since Mercury 0.13.1" section to "for Mercury 10.04 beta" 
    and introduce new "since Mercury 10.04 beta" section.

diff --git a/NEWS b/NEWS
index 7bf2009..fa0bdc3 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,14 @@
-NEWS since Mercury 0.13.1
--------------------------
+NEWS since Mercury 10.04 beta 
+-----------------------------
+
+Changes to the Mercury standard library:
+
+* New predicates have been added to the assoc_list module, these are
+  map_keys_only/3 map_values_only/3 and map_values/3.  They complement the
+  functions of the same name.
+
+NEWS for Mercury 10.04 beta
+---------------------------
 
 Changes to the release numbering:
 
diff --git a/library/assoc_list.m b/library/assoc_list.m
index 786fce2..a98cfc9 100644
--- a/library/assoc_list.m
+++ b/library/assoc_list.m
@@ -78,11 +78,24 @@
 :- pred assoc_list.remove(assoc_list(K, V)::in, K::in, V::out,
     assoc_list(K, V)::out) is semidet.
 
+:- pred assoc_list.map_keys_only(pred(K, L), 
+    assoc_list(K, V), assoc_list(L, V)).
+:- mode assoc_list.map_keys_only(pred(in, out) is det, in, out) is det.
+
 :- func assoc_list.map_keys_only(func(K) = L, assoc_list(K, V))
     = assoc_list(L, V).
+
+:- pred assoc_list.map_values_only(pred(V, W), 
+    assoc_list(K, V), assoc_list(K, W)).
+:- mode assoc_list.map_values_only(pred(in, out) is det, in, out) is det.
+
 :- func assoc_list.map_values_only(func(V) = W, assoc_list(K, V))
     = assoc_list(K, W).
 
+:- pred assoc_list.map_values(pred(K, V, W), 
+    assoc_list(K, V), assoc_list(K, W)).
+:- mode assoc_list.map_values(pred(in, in, out) is det, in, out) is det.
+
 :- func assoc_list.map_values(func(K, V) = W, assoc_list(K, V))
     = assoc_list(K, W).
 
@@ -172,16 +185,31 @@ assoc_list.keys(AL) = Ks :-
 assoc_list.values(AL) = Vs :-
     assoc_list.values(AL, Vs).
 
+assoc_list.map_keys_only(_P, [], []).
+assoc_list.map_keys_only(P, [K0 - V | KVs0], [K - V | KVs]) :-
+    P(K0, K),
+    assoc_list.map_keys_only(P, KVs0, KVs).
+
 assoc_list.map_keys_only(_F, []) = [].
 assoc_list.map_keys_only(F, [K0 - V | KVs0]) = [K - V | KVs] :-
     K = F(K0),
     KVs = assoc_list.map_keys_only(F, KVs0).
 
+assoc_list.map_values_only(_P, [], []).
+assoc_list.map_values_only(P, [K - V0 | KVs0], [K - V | KVs]) :-
+    P(V0, V),
+    assoc_list.map_values_only(P, KVs0, KVs).
+
 assoc_list.map_values_only(_F, []) = [].
 assoc_list.map_values_only(F, [K - V0 | KVs0]) = [K - V | KVs] :-
     V = F(V0),
     KVs = assoc_list.map_values_only(F, KVs0).
 
+assoc_list.map_values(_P, [], []).
+assoc_list.map_values(P, [K - V0 | KVs0], [K - V | KVs]) :-
+    P(K, V0, V),
+    assoc_list.map_values(P, KVs0, KVs).
+
 assoc_list.map_values(_F, []) = [].
 assoc_list.map_values(F, [K - V0 | KVs0]) = [K - V | KVs] :-
     V = F(K, V0),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20100317/f9a10f59/attachment.sig>


More information about the reviews mailing list