Skip to main content

Making Mercury Programs Tail Recursive

  • Conference paper
Book cover Logic-Based Program Synthesis and Transformation (LOPSTR 1999)

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 1817))

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Aït-Kaci, H.: Warren’s Abstract Machine: A Tutorial Reconstruction. MIT Press, Cambridge (1991)

    Google Scholar 

  2. 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)

    Article  MATH  MathSciNet  Google Scholar 

  3. Bloch, C.: Source-to-source transformation of logic programs. Master’s thesis, Weizmann Institue of Science (November 1984)

    Google Scholar 

  4. Boehm, H.-J.: Dynamic memory allocation and garbage collection. Computers in Physics 9(3), 297–303 (1995)

    Google Scholar 

  5. Brough, D.R., Hogger, C.J.: Compiling associativity into logic programs. Journal of Logic Programming 4(4), 345–359 (1987)

    Article  MATH  MathSciNet  Google Scholar 

  6. Brough, D.R., Hogger, C.J.: Grammar-related transformations of logic programs. New Generation Computing 9, 115–134 (1991)

    Article  MATH  Google Scholar 

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

    Google Scholar 

  8. 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)

    Google Scholar 

  9. 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)

    Google Scholar 

  10. 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)

    Google Scholar 

  11. 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)

    Google Scholar 

  12. Pettorossi, A., Proietti, M.: Transformation of logic programs: Foundations and techniques. Journal of Logic Programming 19, 20, 261–320 (1994)

    Article  MathSciNet  Google Scholar 

  13. 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)

    Article  MATH  Google Scholar 

  14. Speirs, C., Somogyi, Z., Søndergaard, H.: Termination analysis for Mercury. In: Proceedings of the Fourth International Static Analysis Symposium, pp. 157–171 (1997)

    Google Scholar 

  15. Taylor, A.: High Performance Prolog Implementation. PhD thesis, University of Sydney (1991)

    Google Scholar 

  16. Mercury Team. Mercury 0.9 (December 1999), Available from http://www.cs.mu.oz.au/mercury/

  17. 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)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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

Publish with us

Policies and ethics