Syntactic extensions in the programming language LISP
暂无分享,去创建一个
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.