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

Tyson Dowd trd at cs.mu.OZ.AU
Tue Oct 20 00:31:11 AEST 1998


> +map__intersect_2(AssocList1, AssocList2, CommonPred, Common0, Common) :-
> +	(
> +		AssocList1 = [],
> +		AssocList2 = [],
> +		Common = Common0
> +	;
> +		AssocList1 = [_ | _],
> +		AssocList2 = [],
> +		Common = Common0
> +	;
> +		AssocList1 = [],
> +		AssocList2 = [_ | _],
> +		Common = Common0
> +	;
> +		AssocList1 = [Key1 - Value1 | AssocTail1],
> +		AssocList2 = [Key2 - Value2 | AssocTail2],
> +		compare(R, Key1, Key2),
> +		(
> +			R = (=),
> +			call(CommonPred, Value1, Value2, Value),
> +			map__det_insert(Common0, Key1, Value, Common1),
> +			map__intersect_2(AssocTail1, AssocList2, CommonPred,
> +				Common1, Common)

Because there will be at most one of each key in the assoc_lists, you
can in fact use AssocTail2 instead of AssocList2 in the recursive call
-- in next call Key1 will always be greater than Key2.

> +map__union_2(AssocList1, AssocList2, CommonPred, Common0, Common) :-
> +	(
> +		AssocList1 = [],
> +		AssocList2 = [],
> +		Common = Common0
> +	;
> +		AssocList1 = [_ | _],
> +		AssocList2 = [],
> +		map__det_insert_from_assoc_list(Common0, AssocList1, Common)
> +	;
> +		AssocList1 = [],
> +		AssocList2 = [_ | _],
> +		map__det_insert_from_assoc_list(Common0, AssocList2, Common)
> +	;
> +		AssocList1 = [Key1 - Value1 | AssocTail1],
> +		AssocList2 = [Key2 - Value2 | AssocTail2],
> +		compare(R, Key1, Key2),
> +		(
> +			R = (=),
> +			call(CommonPred, Value1, Value2, Value),
> +			map__det_insert(Common0, Key1, Value, Common1),
> +			map__union_2(AssocTail1, AssocList2, CommonPred,
> +				Common1, Common)

Same is true here.

You need to mention changes to the interfaces in the library in the NEWS
file.

Otherwise this change is fine and I'm happy for you to commit it.

-- 
Those who would give up essential liberty to purchase a little temporary
safety deserve neither liberty nor safety.     - Benjamin Franklin

Tyson Dowd   <tyson at tyse.net>   http://tyse.net



More information about the developers mailing list