skip to main content
10.1145/581478.581500acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
Article

There and back again

Published:17 September 2002Publication History

ABSTRACT

We present a programming pattern where a recursive function traverses a data structure---typically a list---at return time. The idea is that the recursive calls get us there (typically to a base case) and the returns get us back again while traversing the data structure. We name this programming pattern of traversing a data structure at return time "There And Back Again" (TABA).The TABA pattern directly applies to computing a symbolic convolution. It also synergizes well with other programming patterns, e.g., dynamic programming and traversing a list at double speed. We illustrate TABA and dynamic programming with Catalan numbers. We illustrate TABA and traversing a list at double speed with palindromes and we obtain a novel solution to this traditional exercise.A TABA-based function written in direct style makes full use of an Algol-like control stack and needs no heap allocation. Conversely, in a TABA-based function written in continuation-passing style, the continuation acts as a list iterator. In general, the TABA pattern saves one from constructing intermediate lists in reverse order.

References

  1. Richard S. Bird. Using circular programs to eliminate multiple traversals of data. Acta Informatica, 21:239--250, 1984.Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. William Clinger, Anne H. Hartheimer, and Eric M. Ost. Implementation strategies for first-class continuations. Higher-Order and Symbolic Computation, 12(1):7--45, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Olivier Danvy and Andrzej Filinski. Representing control, a study of the CPS transformation. Mathematical Structures in Computer Science, 2(4):361--391, 1992.Google ScholarGoogle ScholarCross RefCross Ref
  4. Olivier Danvy and Julia L. Lawall. Back to direct style II: First-class continuations. In William Clinger, editor, Proceedings of the 1992 ACM Conference on Lisp and Functional Programming, LISP Pointers, Vol. V, No. 1, pages 299--310, San Francisco, California, June 1992. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Ronald L. Graham, Donald E. Knuth, and Oren Patashnik. Concrete Mathematics. Addison-Wesley, 1989.Google ScholarGoogle Scholar
  6. Luo Jian-Jin. Catalan numbers in the history of mathematics in China. In H.P. Yap et al., editor, Combinatorics and Graph Theory: Proc. Spring School and International Conference on Combinatorics, pages 68--70, Hefei, China, 1993. World Scientific.Google ScholarGoogle Scholar
  7. John Launchbury and Tim Sheard. Warm fusion: Deriving build-cata's from recursive definitions. In Simon Peyton Jones, editor, Proceedings of the Seventh ACM Conference on Functional Programming and Computer Architecture, pages 314--323, La Jolla, California, June 1995. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Y. Annie Liu and Scott D. Stoller. From recursion to iteration: what are the optimizations? In Julia L. Lawall, editor, Proceedings of the 2000 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation, SIGPLAN Notices, Vol. 34, No~11, pages 73--82, Boston, Massachusetts, November 2000. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Alberto Pettorossi and Maurizio Proietti. Importing and exporting information in program development. In Dines Bjørner, Andrei P. Ershov, and Neil D. Jones, editors, Partial Evaluation and Mixed Computation, pages 405--425. North-Holland, 1988.Google ScholarGoogle Scholar
  10. Alberto Pettorossi and Maurizio Proietti. A comparative revisitation of some program transformation techniques. In Olivier Danvy, Robert Glück, and Peter Thiemann, editors, Partial Evaluation, number 1110 in Lecture Notes in Computer Science, pages 355--385, Dagstuhl, Germany, February 1996. Springer-Verlag. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Jagadguru Swami Sri Bharati Krsna Tirthaji Maharaja. Vedic Mathematics. Motilal Banarsidass Publishers Private Limited, 1992.Google ScholarGoogle Scholar
  12. Guy L. Steele Jr. Debunking the `expensive procedure call' myth. In Proceedings of the ACM National Conference, pages 133--162, Seattle, Washington, October 1977. Extended version available as MIT AI Memo 443. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Guy L. Steele Jr. Common Lisp: The Language. Digital Press, 1984. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Robert A. Sulanke. Moments of generalized Motzkin paths. Journal of Integer Sequences, 3(00.1.1), 2000. http://www.math.uwaterloo.ca/JIS/.Google ScholarGoogle Scholar
  15. Hongwei Xi and Frank Pfenning. Dependent types in practical programming. In Alex Aiken, editor, Proceedings of the Twenty-Sixth Annual ACM Symposium on Principles of Programming Languages, pages 214--227, San Antonio, Texas, January 1999. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. There and back again

                    Recommendations

                    Comments

                    Login options

                    Check if you have access through your login credentials or your institution to get full access on this article.

                    Sign in
                    • Published in

                      cover image ACM Conferences
                      ICFP '02: Proceedings of the seventh ACM SIGPLAN international conference on Functional programming
                      October 2002
                      294 pages
                      ISBN:1581134878
                      DOI:10.1145/581478
                      • cover image ACM SIGPLAN Notices
                        ACM SIGPLAN Notices  Volume 37, Issue 9
                        September 2002
                        283 pages
                        ISSN:0362-1340
                        EISSN:1558-1160
                        DOI:10.1145/583852
                        Issue’s Table of Contents

                      Copyright © 2002 ACM

                      Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

                      Publisher

                      Association for Computing Machinery

                      New York, NY, United States

                      Publication History

                      • Published: 17 September 2002

                      Permissions

                      Request permissions about this article.

                      Request Permissions

                      Check for updates

                      Qualifiers

                      • Article

                      Acceptance Rates

                      ICFP '02 Paper Acceptance Rate24of76submissions,32%Overall Acceptance Rate333of1,064submissions,31%

                      Upcoming Conference

                      ICFP '24

                    PDF Format

                    View or Download as a PDF file.

                    PDF

                    eReader

                    View online with eReader.

                    eReader