Interruptible iterators

This paper introduces interruptible iterators, a language feature that makes expressive iteration abstractions much easier to implement. Iteration abstractions are valuable for software design, as shown by their frequent use in well-designed data structure libraries such as the Java Collections Framework. While Java iterators support iteration abstraction well from the standpoint of client code, they are awkward to implement correctly and efficiently, especially if the iterator needs to support imperative update of the underlying collection, such as removing the current element. Some languages, such as CLU and C# 2.0, support iteration through a limited coroutine mechanism, but these mechanisms do not support imperative updates. Interruptible iterators are more powerful coroutines in which the loop body is able to interrupt the iterator with requests to perform updates. Interrupts are similar to exceptions, but propagate differently and have resumption semantics. Interruptible iterators have been implemented as part of the JMatch programming language, an extended version of Java. A JMatch reimplementation of the Java Collections Framework shows that implementations can be made substantially shorter and simpler; performance results show that this language mechanism can also be implemented efficiently.

[1]  Andrew W. Appel,et al.  Standard ML of New Jersey , 1991, PLILP.

[2]  David R. Musser,et al.  STL tutorial and reference guide , 2001 .

[3]  Fred L. Drake,et al.  The Python Language Reference Manual , 1999 .

[4]  Mary Shaw,et al.  Abstraction and verification in Alphard: Defining and specifying iteration and generators , 1977, Commun. ACM.

[5]  Clemens A. Szyperski,et al.  Iteration abstraction in Sather , 1996, TOPL.

[6]  Michael R. Clarkson,et al.  Polyglot: An Extensible Compiler Framework for Java , 2003, CC.

[7]  Barbara Liskov,et al.  Aspects Of Implementing CLU , 1978, ACM Annual Conference.

[8]  David R. Musser,et al.  STL tutorial and reference guide, second edition: C++ programming with the standard template library , 2001 .

[9]  Emden R. Gansner,et al.  The standard ML basis library , 2002 .

[10]  David H. D. Warren,et al.  Prolog - the language and its implementation compared with Lisp , 1977, Artificial Intelligence and Programming Languages.

[11]  Jonathan Rees,et al.  Revised3 report on the algorithmic language scheme , 1986, SIGP.

[12]  Mitchell Wand,et al.  Obtaining Coroutines with Continuations , 1986, Comput. Lang..

[13]  Bjarne Stroustrup,et al.  C++ Programming Language , 1986, IEEE Softw..

[14]  David Maier,et al.  Readings in Object-Oriented Database Systems , 1989 .

[15]  Andrew C. Myers,et al.  JMatch: Java plus Pattern Matching , 2002 .

[16]  Guy L. Steele,et al.  The Java Language Specification , 1996 .

[17]  John B. Goodenough,et al.  Exception handling design issues , 1975, SIGP.

[18]  Andrew C. Myers,et al.  Parameterized types for Java , 1997, POPL '97.

[19]  Fernando Pereira,et al.  Prolog - the language and its implementation compared with Lisp , 1977, Artificial Intelligence and Programming Languages.

[20]  Bjorn Kirkerud Object-Oriented Programming with SIMULA , 1989 .

[21]  Harold Abelson,et al.  Revised5 report on the algorithmic language scheme , 1998, SIGP.

[22]  Craig Schaffert,et al.  CLU Reference Manual , 1984, Lecture Notes in Computer Science.

[23]  David R. Hanson,et al.  Generators in Icon , 1981, TOPL.

[24]  R. Kent Dybvig,et al.  Revised5 Report on the Algorithmic Language Scheme , 1986, SIGP.

[25]  Ole Lehrmann Madsen,et al.  Object-oriented programming in the BETA programming language , 1993 .

[26]  Robin Milner,et al.  Definition of standard ML , 1990 .

[27]  Niklaus Wirth,et al.  Programming in Modula-2 , 1985, Texts and Monographs in Computer Science.

[28]  Craig Schaffert,et al.  Abstraction mechanisms in CLU , 1977, Commun. ACM.

[29]  H. Lipkin Where is the ?c? , 1978 .