[m-dev.] for review: new predicates in map.m

Andrew Bromage bromage at cs.mu.OZ.AU
Tue Oct 20 07:33:57 AEST 1998


G'day all.

Zoltan Somogyi wrote:

> +	% Given a map, return a list of all the keys in the map,
> +	% in sorted order.
> +:- pred map__sorted_keys(map(K, _V), list(K)).
> +:- mode map__sorted_keys(in, out) is det.

There are already parts of the compiler which assume that map__keys/2
returns the keys in sorted order.  (I know because I wrote one or two
of them; after asking, of course. <g>)  Perhaps it would be better to
make that the default behaviour of map__keys/2.

(If order is not important, we could introduce another predicate which
returns the keys as a set.)

> -	% convert an association list to a map
> +	% Convert a map to an association list which is sorted on the keys.
> +:- pred map__to_sorted_assoc_list(map(K,V), assoc_list(K,V)).
> +:- mode map__to_sorted_assoc_list(in, out) is det.

I don't think any code relies on this, but might as well change the
behaviour of this while you're at it.

> +	% Calls map__intersect. Abort (with the last argument as the message)
> +	% if map__intersect fails.

s/Abort/Aborts/

Making the last argument the message seems to be a bit of a novelty as
far as the library goes.  For consistency, it might be better for the
implementation to supply a neutral error message, and if you need
something more specific, use if-then-else and error/1.

Cheers,
Andrew Bromage



More information about the developers mailing list