Programming Errors in Traversal Programs Over Structured Data

Ralf Lämmel, Simon Thompson, Markus Kaiser
2009 Electronical Notes in Theoretical Computer Science  
Traversal strategies provide an established means of describing automated queries, analyses, transformations, and other non-trivial computations on deeply structured data (including, most notably, data representations of software artifacts such as programs). The resulting traversal programs are prone to programming errors. We are specifically concerned with errors that go beyond classic type errors, in particular: (i) divergence of traversal, (ii) unintentional extent of traversal into data,
more » ... i) trivial traversal results, (iv) inapplicability of the constituents of a traversal program along traversal. We deliver a taxonomy of programming errors, and start attacking some of them by refinements of traversal programming. with rewriting-like capabilities [22, 23, 13, 24, 21] so that traversals (perhaps even highly reusable traversal strategies) are programmable. Despite these advances, the use and the definition of programmable traversal strategies has remained the domain of the expert, rather than gaining wider usage. This could in part be due to necessary language, library, and tool support, but we contend that the principal obstacle to wider adoption is the severity of some possible pitfalls, which make it difficult to use strategies in practice. Some of the programming errors that arise are familiar, e.g., type errors, but other errors are of a novel nature. Their appearance can be offputting to the newcomer to the field, and it can limit the productivity even of experienced strategists. This paper is a first step in a programme which aims to make strategic programming more accessible and approachable through providing an introduction to -and indeed a taxonomy of -some of the common pitfalls of strategic programming. We also begin refining strategic programming so that the next generation of strategic programming may be considerably easier to use. A running example. To use a purposely simple example, consider the transformation problem of "incrementing all numbers in a term". (Clearly, programming errors become more severe with increasing the problem size.) Suppose is the rewrite rule that maps any given number n to n+1. It remains to compose a strategy that can essentially iterate over any term. Here is an indication of some of the things that may go wrong with the application of the composed strategy: • It fails to terminate. • It fails to find numbers in the input term. • It fails, i.e., it returns a trivial failure term. • It increments some numbers in the input term more than once.
doi:10.1016/j.entcs.2009.09.045 fatcat:m4bi5rzs3zhmrcdfd5a3scw4cm