[m-dev.] for review: aggregate/4

Fergus Henderson fjh at cs.mu.oz.au
Mon May 26 16:30:43 AEST 1997


Thomas Charles CONWAY, you wrote:
> 
> Can someone please review the following addition to the library?

I'd like to hear Peter Schachte's comments on this change.
I think he has been working on something like this.

> library/std_util.m:
> 	Add aggregate/4 and unsorted_aggregate/4.
> 	Although these predicates are currently implemented in terms of
> 	[unsorted_]solutions and list__foldl, in theory, they can be
> 	implemented more efficiently (at least unsorted_aggregate can,
> 	and aggregate probably can).

I don't think aggregate can be.  You need to sort the solutions
before folding them, and you need to have found all solutions
before you can make the first call to the accumulator.

Given that there is no efficiency advantage, aggregate/4 doesn't
really buy you much over just calling solutions/2 and list__foldl/4.
Is it really worth adding to the library?

> +% aggregate/4 generates all the solutions to a predicate and applies
> +% an accumulator predicate to each solution in turn. XXX how can we
> +% better describe aggregation?

How about the following:

	% unsorted_aggregate/4 generates all the solutions to a predicate
	% and applies an accumulator predicate to each solution in turn:
	%
	% unsorted_aggregate(Generator, Accumulator, Acc0, Acc) <=>
	% 	unsorted_solutions(Generator, Solutions),
	% 	list__foldl(Accumulator, Solutions, Acc0, Acc).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list