[m-dev.] Re: The Great Computer Language Shootout

Thomas Conway conway at cs.mu.OZ.AU
Wed Jan 10 08:05:14 AEDT 2001


On Wed, Jan 10, 2001 at 04:26:14AM EST, Ralph Becket wrote:
> 3. We could do with a few utility functions in the library that
> do things like iterate a function until some condition is reached and
> iterate over a range of the integers.  It happens more than you might
> imagine, out there.

A predicate that I seem to have written too many times is:

:- pred for(int, int, pred(int, T, T), T, T).
:- mode for(in, in, pred(in, in, out) is det, in, out) is det.
:- mode for(in, in, pred(in, di, uo) is det, di, uo) is det.

for(Min, Max, Pred) -->
	( { Min =< Max } ->
		call(Pred, Min),
		for(Min + 1, Max, Pred)
	;
		[]
	).

Does it belong in int.m?

-- 
 Thomas Conway              Mercurian )O+  
 <conway at cs.mu.oz.au>       Every sword has two edges.
--------------------------------------------------------------------------
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