The traditional macro processing systems used in Lisp-family languages have a number of shortcomings. We identify five problems with the declaration tools customarily available to programmers. First, the declarations themselves are hard to read and write. Second, the declarations provide little explicit information about the form macro calls are to take. Third, syntactic checking of macro calls is usually ignored. Fourth, the notion of a macro binding for an identifier gives rise to a poor understanding of what macros really should be. Fifth, the unrestricted capabilities of the language used to declare macros cause some to take advantage of macros in ways inconsistent with their role as textual abstractions. Furthermore, the conventional algorithm used for the expansion of macro calls within Lisp often causes the inadvertent capture of an identifier appearing within the macro call by a macro-generated, binding instance of the same identifier. Lisp programmers have developed a few techniques for avoiding this problem, but they all have depended upon the macro writer taking some sort of special preventative action.We examine several existing macro processors, both inside and outside of the Lisp-family. We then enumerate a set of design principles for macro processing systems. These principles are general enough that they apply to the organization of macro processing systems for a large number of high-level languages. Taking our principles as guidelines, we design a new macro processing system for Lisp. The new macro declaration tool addresses each of the five problems from which the traditional tools suffer. A description of the use of our tool and an annotated presentation of its implementation are provided. We also develop a new macro expansion algorithm that eliminates the capturing problem. The macro expander has the responsibility for avoiding the unwanted capture of identifiers appearing within macro calls.
Cited By
- Burmako E Scala macros: let our powers combine! Proceedings of the 4th Workshop on Scala, (1-10)
- Tobin-Hochstadt S, St-Amour V, Culpepper R, Flatt M and Felleisen M Languages as libraries Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation, (132-141)
- Tobin-Hochstadt S, St-Amour V, Culpepper R, Flatt M and Felleisen M (2019). Languages as libraries, ACM SIGPLAN Notices, 46:6, (132-141), Online publication date: 4-Jun-2011.
- Sperber M, Dybvig R, Flatt M, Van straaten A, Findler R and Matthews J (2009). Revised6 report on the algorithmic language scheme, Journal of Functional Programming, 19:S1, (1-301), Online publication date: 1-Aug-2009.
- Dybvig R The development of Chez Scheme Proceedings of the eleventh ACM SIGPLAN international conference on Functional programming, (1-12)
- Dybvig R (2006). The development of Chez Scheme, ACM SIGPLAN Notices, 41:9, (1-12), Online publication date: 16-Sep-2006.
- Calcagno C, Taha W, Huang L and Leroy X Implementing multi-stage languages using ASTs, Gensym, and reflection Proceedings of the 2nd international conference on Generative programming and component engineering, (57-76)
- Tucker D and Krishnamurthi S Pointcuts and advice in higher-order languages Proceedings of the 2nd international conference on Aspect-oriented software development, (158-167)
- Waddell O and Dybvig R Extending the scope of syntactic abstraction Proceedings of the 26th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, (203-215)
- Abelson H, Dybvig R, Haynes C, Rozas G, Adams Iv N, Friedman D, Kohlbecker E, Steele G, Bartley D, Halstead R, Oxley D, Sussman G, Brooks G, Hanson C, Pitman K and Wand M (1998). Revised Report on the Algorithmic Language Scheme, Higher-Order and Symbolic Computation, 11:1, (7-105), Online publication date: 1-Aug-1998.
- Steele G and Gabriel R The evolution of Lisp History of programming languages---II, (233-330)
- Tessman T (1995). Adding generic functions to Scheme, ACM SIGPLAN Notices, 30:4, (45-50), Online publication date: 1-Apr-1995.
- Bove A and Arbilla L A confluent calculus of Macro expansion and evaluation Proceedings of the 1992 ACM conference on LISP and functional programming, (278-287)
- Bove A and Arbilla L (2019). A confluent calculus of Macro expansion and evaluation, ACM SIGPLAN Lisp Pointers, V:1, (278-287), Online publication date: 1-Jan-1992.
- Abelson H, Dybvig R, Haynes C, Rozas G, Adams N, Friedman D, Kohlbecker E, Steele G, Bartley D, Halstead R, Oxley D, Sussman G, Brooks G, Hanson C, Pitman K, Wand M, Clinger W and Rees J (1991). Revised4 report on the algorithmic language scheme, ACM SIGPLAN Lisp Pointers, IV:3, (1-55), Online publication date: 1-Jul-1991.
- Yigit O (1988). Readings in scheme, ACM SIGPLAN Lisp Pointers, 2:1, (56-61), Online publication date: 1-Jul-1988.
- Kohlbecker E and Wand M Macro-by-example: Deriving syntactic transformations from their specifications Proceedings of the 14th ACM SIGACT-SIGPLAN symposium on Principles of programming languages, (77-84)
- Humphrey S and Krovetz B (1987). SELECTED AI-RELATED DISSERTATIONS, ACM SIGART Bulletin:100, (25-31), Online publication date: 1-Apr-1987.
- Rees J and Clinger W (1986). Revised3 report on the algorithmic language scheme, ACM SIGPLAN Notices, 21:12, (37-79), Online publication date: 1-Dec-1986.
Index Terms
- Syntactic extensions in the programming language LISP
Recommendations
Prolog - the language and its implementation compared with Lisp
Proceedings of the 1977 symposium on Artificial intelligence and programming languagesProlog is a simple but powerful programming language founded on symbolic logic. The basic computational mechanism is a pattern matching process (“unification”) operating on general record structures (“terms” of logic). We briefly review the language and ...
Experiences with a simple structured programming language
SIGCSE '74: Proceedings of the fourth SIGCSE technical symposium on Computer science educationA great deal of interest has developed in structured programming [Dahl, Dijkstra, and Hoare, 1972] during the past few years. This paper is concerned with some experiences obtained in the use of a structured programming language in the computer science ...
Implementing aspect-oriented programming constructs as modular language extensions
Extensible programming languages and their compilers are experimental systems that use highly modular specifications of languages and language extensions in order to allow a variety of language features to be easily imported, by the programmer, into his ...