[mercury-users] accumulator introduction

Peter Ross petdr at cs.mu.OZ.AU
Fri Jun 23 17:37:43 AEST 2000


On Fri, Jun 23, 2000 at 04:42:28PM +1000, David Overton wrote:
> On Fri, Jun 23, 2000 at 01:11:05PM +1000, Michael Day wrote:
> > 
> > Is there any way for Mercury to automatically convert this predicate to
> > use an accumulator, or is it condemned to overflow the detstack forever?
> > 
> > sum(Input, Output) :-
> >     ( if Input = 0 then
> >         Output = Input
> >     else
> >         sum(Input-1, Output0),
> >         Output = Output0 + Input
> >     ).
> > 
> > Adding an accumulator manually to make it tail recursive gives performance
> > quite close to a C loop:
> > 
> > for (i = 0; i <= Input; ++i) sum += i;
> > 
> > which is rather nice. But it would be nicer if it added the accumulator
> > itself. Is this possible?
> > 
> 
Unfortunately when I rewrote the module to support the new update state
transformation.  I removed the support for if-then-elses, I will add
that back in the next few days.

When it is back in all you need to do is add the option
'--introduce-accumulators' to your command line.

Pete
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list