[m-rev.] diff: two new library predicates

Fergus Henderson fjh at cs.mu.OZ.AU
Mon May 26 20:39:19 AEST 2003


On 26-May-2003, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> +++ library/map.m	26 May 2003 10:00:08 -0000
> @@ -337,6 +337,21 @@
> +	% Given two maps M1 and M2, create a third map M3 that has only the
> +	% keys that occur in both M1 and M2. For keys that occur in both M1
> +	% and M2, compute the corresponding values. If they are the same,
> +	% include the key/value pair in M3. If they differ, do not include the
> +	% key in M3.
> +	%
> +	% This predicate effectively considers the input maps to be sets of
> +	% key/value pairs, computes the intersection of those two sets, and
> +	% returns the map corresponding to the intersection.
> +	%
> +	% map__common_subset is very similar to map__intersect, but can succeed
> +	% even with an output map that does not contain an entry for a key
> +	% value that occurs in both input maps.
> +:- func map__common_subset(map(K, V), map(K, V)) = map(K, V).

Is that really worth adding to the standard library?
The same functionality can be implemented using the existing interface
(e.g. see below), so is it really sufficiently useful to be worth adding
to the standard library?  How often will it get used?

	common_subset(M1, M2) = M3 :-
		S1 = set.from_sorted_list(map.to_sorted_assoc_list(M1)),
		S2 = set.from_sorted_list(map.to_sorted_assoc_list(M2)),
		S3 = S1 `set.intersect` S2,
		M3 = map.from_sorted_assoc_list(set.sorted_list_to_set(S3)).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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