[m-dev.] For review: iteration support added to std_util.m

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Jan 12 14:20:56 AEDT 2001


On 11-Jan-2001, Ralph Becket <rbeck at microsoft.com> wrote:
> Added funcs and preds to support common iteration schemes.
> 
> library/std_util.m
> 	Added the following:
> 	iterate/5		- fairly general indexed iteration
> 	iterate_dcg//4
> 	over_range/4		- iteration indexed by ascending integer
> range
> 	over_range_dcg//3
> 	iterate_until/3		- unindexed iteration until some condition
> 	iterate_until_dcg//1

Without expression any opinion on the desirability of
adding these new functions (I haven't thought about it yet),
I'd just like to make some points about what should be done if they
are added:

	- There should be some test cases for these.
	- They should be mentioned in the NEWS file.

> Index: std_util.m
> +	% A version of iterate/5 specialised for ascending integer
> +	% sequences.
> +	%
> +:- func over_range(int, int, func(int, T) = T, T) = T.

The documentation for this does not clearly describe the semantics.
semantics.

> +over_range(Lo, Hi, Fn, X) =
> +	iterate(Lo, >=(Hi), plus(1), Fn, X).

I was about to point out the bug in this code, until eventually
I realized that it was correct.
But the partially applied form of `>=' is confusing, IMHO.
I think it would be clearer to write

	iterate(Lo, (pred(Xi::in) is semidet :- Xi =< Hi), plus(1), Fn, X).

Also s/Lo/Low/ and s/Hi/High/

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