[m-dev.] for review: assoc_list__keys_and_values
Zoltan Somogyi
zs at cs.mu.OZ.AU
Mon Jan 8 14:36:30 AEDT 2001
library/assoc_list.m:
Add a predicate to get the keys and values as separate lists
simultaneously.
Zoltan.
Index: assoc_list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/assoc_list.m,v
retrieving revision 1.12
diff -u -b -r1.12 assoc_list.m
--- assoc_list.m 2000/11/12 08:51:32 1.12
+++ assoc_list.m 2001/01/02 07:42:20
@@ -1,5 +1,5 @@
%---------------------------------------------------------------------------%
-% Copyright (C) 1995-1997, 1999-2000 The University of Melbourne.
+% Copyright (C) 1995-1997, 1999-2001 The University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%---------------------------------------------------------------------------%
@@ -56,6 +56,9 @@
:- func assoc_list__values(assoc_list(K, V)) = list(V).
+:- pred assoc_list__keys_and_values(assoc_list(K, V), list(K), list(V)).
+:- mode assoc_list__keys_and_values(in, out, out) is det.
+
% Find the first element of the association list that matches
% the given key, and return the associated value.
@@ -122,6 +125,10 @@
assoc_list__values([], []).
assoc_list__values([_ - V | KVs], [V | Vs]) :-
assoc_list__values(KVs, Vs).
+
+assoc_list__keys_and_values([], [], []).
+assoc_list__keys_and_values([K - V | KVs], [K | Ks], [V | Vs]) :-
+ assoc_list__keys_and_values(KVs, Ks, Vs).
assoc_list__search([K - V | KVs], Key, Value) :-
( K = Key ->
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list