Abstract
We present two optimizations for making Mercury programs tail recursive. Both operate by taking computations that occur after a recursive call and moving them before the recursive call, modifying them as necessary. The first optimization moves calls to associative predicates; it is a pure source to source transformation. The second optimization moves construction unifications; it required extensions to the mode system (to record aliases) and to the parameter passing convention (to allow arguments to be returned in memory). The two optimizations are designed to work together, and can make a large class of programs tail recursive.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Aït-Kaci, H.: Warren’s Abstract Machine: A Tutorial Reconstruction. MIT Press, Cambridge (1991)
Bigot, P.A., Debray, S.: Return value placement and tail call optimization in high level languages. Journal of Logic Programming 38(1), 1–29 (1999)
Bloch, C.: Source-to-source transformation of logic programs. Master’s thesis, Weizmann Institue of Science (November 1984)
Boehm, H.-J.: Dynamic memory allocation and garbage collection. Computers in Physics 9(3), 297–303 (1995)
Brough, D.R., Hogger, C.J.: Compiling associativity into logic programs. Journal of Logic Programming 4(4), 345–359 (1987)
Brough, D.R., Hogger, C.J.: Grammar-related transformations of logic programs. New Generation Computing 9, 115–134 (1991)
Büyükyildiz, H., Flener, P.: Generalised logic program transformation schemas. In: Fuchs, N.E. (ed.) Proceedings of the Seventh International Workshop on Logic Program Synthesis and Transformation, pp. 45–65 (1997)
Debray, S.K.: Optimizing almost-tail-recursive Prolog programs. In: Proceedings of the International Symposium on Functional Programming Languages and Computer Architecture, pp. 204–219 (1985)
Debray, S.K.: Unfold/fold transformations and loop optimization of logic programs. In: Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, pp. 297–307 (1988)
Demoen, B., de la Banda, M.G., Harvey, W., Marriott, K., Stuckey, P.J.: Herbrand constraint solving in HAL. In: Proceedings of the Sixteenth International Conference on Logic Programming, pp. 260–274 (1999)
Henderson, F., Conway, T., Somogyi, Z., Jeffery, D.: The Mercury language reference manual. Technical Report 96/10, Department of Computer Science, University of Melbourne, Australia (1996)
Pettorossi, A., Proietti, M.: Transformation of logic programs: Foundations and techniques. Journal of Logic Programming 19, 20, 261–320 (1994)
Somogyi, Z., Henderson, F., Conway, T.: The execution algorithm of Mercury: an efficient purely declarative logic programming language. Journal of Logic Programming 29(1–3), 17–64 (1996)
Speirs, C., Somogyi, Z., Søndergaard, H.: Termination analysis for Mercury. In: Proceedings of the Fourth International Static Analysis Symposium, pp. 157–171 (1997)
Taylor, A.: High Performance Prolog Implementation. PhD thesis, University of Sydney (1991)
Mercury Team. Mercury 0.9 (December 1999), Available from http://www.cs.mu.oz.au/mercury/
Wadler, P.: Listlessness is better than laziness: Lazy evaluation and garbage collection at compile-time. In: Proceedings of ACM Symposium on Lisp and Functional Programming, pp. 45–52 (1984)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2000 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Ross, P., Overton, D., Somogyi, Z. (2000). Making Mercury Programs Tail Recursive. In: Bossi, A. (eds) Logic-Based Program Synthesis and Transformation. LOPSTR 1999. Lecture Notes in Computer Science, vol 1817. Springer, Berlin, Heidelberg. https://doi.org/10.1007/10720327_12
Download citation
DOI: https://doi.org/10.1007/10720327_12
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-67628-7
Online ISBN: 978-3-540-45148-8
eBook Packages: Springer Book Archive