[mercury-users] accumulator introduction
David Overton
dmo at cs.mu.OZ.AU
Fri Jun 23 16:42:28 AEST 2000
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?
>
Have a look at the paper:
@InProceedings{ROS1999,
author = "Peter Ross and David Overton and Zoltan Somogyi",
title = "Making Mercury Programs Tail Recursive",
booktitle = "Proceedings of the 9th International Workshop on
Logic-based Program Synthesis and Transformation (LOPSTR'99)",
year = 1999,
month = sep,
address = "Venice, Italy",
}
available from
http://www.cs.mu.oz.au/research/mercury/information/papers.html
.
Pete, what's the current status of this in the compiler?
David
--
David Overton Department of Computer Science & Software Engineering
PhD Student The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159 http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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