[m-dev.] For review: minor additions to list.m and string.m

schachte at cs.mu.OZ.AU schachte at cs.mu.OZ.AU
Fri Sep 8 19:04:19 AEDT 2000


On  8 Sep, Ralph Becket wrote:

> How about this: `..`/2 is the inclusive ascending series
> 
> 	(N `..` M) = Seq
> 	  <=>  all [I] (index0(Seq, I, X) => (X = N + I, X =< M))
> 
> and add
> 
> 	arith_series(N, M, D) = Seq
> 	  <=>  (      if D > 0 then
> 	                all [I] (index0(Seq, I, X) => (X = N + I * D, X =<
> M))
> 	         else if D < 0 then
> 	                all [I] (index0(Seq, I, X) => (X = N + I * D, X >=
> M))
>                else /* D = 0 */
>                       throw(a_wobbly)
> 	       )

Looks good to me.

> Any takers for geom_series/3?  Or is that of too little use?

I wouldn't think it would be worth adding.  You can always add it later
if there's demand.

But maybe something like

	:- func series(T, pred(T) is semidet, func(T) = T) = list(T).

	series(Init, Test, Inc) =
		(   Test(Init) ->
			[Init | series(Inc(Init), Test, Inc)]
		;   []
		).

would be general enough to be useful often enough to bother with? 
(This is completely untested; I hope it's close enough to correct that
you know what I mean.)  Then if you want a geometric series you can
always write something like series(1, >(1000), *(2)).

Kind of looks a bit like a C for loop, doesn't it?

-- 
Peter Schachte                     The use of COBOL cripples the mind; its
mailto:schachte at cs.mu.OZ.AU        teaching should, therefore, be regarded
http://www.cs.mu.oz.au/~schachte/  as a criminal offense.
PGP: finger schachte at 128.250.37.3      -- E. W. Dijkstra 

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