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

Ralph Becket rbeck at microsoft.com
Fri Jan 12 21:19:27 AEDT 2001


>From Fergus Henderson on 12/01/2001 03:23:11
> 
> 	- There should be some test cases for these.
> 	- They should be mentioned in the NEWS file.

Agreed; I want to get some feedback first before doing the above.

> > 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.

How about...

	over_range(Lo, Hi, Fn, X) computes
	Fn(Hi, ... Fn(Lo + 1, Fn(Lo, X)) ...)     where Lo =< Hi and
	X                                         otherwise

> > +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).

Yes, we've had this discussion before.  I'm happy to make that change if
you think the original confusing.

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

I've been using Lo and Hi as abbreviations for ages; I've changed them to
I and Max respectively.

--
Ralph Becket      |      MSR Cambridge      |      rbeck at microsoft.com 

--------------------------------------------------------------------------
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