[m-dev.] For review: new extras package - curses binding

David Overton dmo at ender.cs.mu.oz.au
Fri Jan 14 15:58:14 AEDT 2000


On Fri, 14 Jan, 2000 at 03:40:54PM EST, Robert Ernst Johann JESCHOFNIK wrote:
> +  % for(Accumulator, Max, Closure, StoreIn, StoreOut)
> +  % perform an operation much like a `for loop' in imperative languages. For
> +  % every value of Accumulator =< Max, call Closure with the current value of
> +  % Accumulator.
> +  %
> +  % Example:
> +  %
> +  % for(0, 5, (pred(Num::in, IO1::di, IO2::uo) is det :-
> +  %     io__print(Num, IO1, IO2)
> +  % ), IO0, IO)
> +  %
> +  % Would print "12345".
> +:- 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, in, out) is semidet, in, out) is semidet.
> +:- mode for(in, in, pred(in, di, uo) is det, di, uo) is det.
> +:- mode for(in, in, pred(in, array_di, array_uo) is det,
> +		array_di, array_uo) is det.
> +
> +%----------------------------------------------------------------------------%
> +
> +:- implementation.
> +
> +for(Min, Max, Pred, Acc0, Acc) :-
> +	( Min =< Max ->
> +		Pred(Min, Acc0, Acc1),
> +		for(Min+1, Max, Pred, Acc1, Acc)
> +	;
> +		Acc = Acc0
> +	).

I reckon this predicate is probably useful enough to go in the
standard library (maybe in std_util.m).  What do others think?

-- 
David Overton       Department of Computer Science & Software Engineering
PhD Student         The University of Melbourne, Australia
+61 3 9344 9159     http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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