This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Writing Hygienic Macros in Scheme with Syntax-Case R. Kent Dybvig Indiana University Computer Science Department Bloomington, IN 47405 [email protected] Copyright c 1992 R. Kent Dybvig August 1992 Abstract This article describes a pattern-based hygienic macro system for Scheme and provides numerous examples of its use. Macros defined using this system are automatically hygienic and referentially transparent . Unlike earlier hygienic macro systems, this system does not require “low level” macros to be written in a different style from “high level” macros. In particular, automatic hygiene, referential transparency, and the ability to use patterns extend to all macro definitions, and there is never any need to explicitly manipulate syntactic environments of any kind. The macro system also supplies a hygiene-preserving mechanism for controlled variable capture, allowing macros to introduce implicit identifier bindings or references. 1 Introduction This article describes a hygienic macro system for Scheme that is similar to the one documented in an appendix to the “Revised 4 Report on the Algorithmic Language Scheme” , with several important differences. Most importantly, there is no practical distinction in this system between “high level” and “low level” macros. Although some macros will not take advantage of the more primitive operators, there is no penalty in terms of loss of automatic hygiene, referential trans- parency, or ease-of-use for those macros that do. In particular, the same pattern matching facilities that were previously available only to high-level macros can now be used in any context. There is never any need to completely rewrite a macro originally written in a high-level style simply because it now requires access to some more primitive feature. Furthermore, there is never any need to explicitly manipulate syntactic environments of any kind. The macro system consists of a set of defining forms, a set of forms for taking apart and putting together syntax, and a set of primitives for manipulating and comparing identifiers. The system is based on a representation of expressions as abstract objects that are different from the commonly used Scheme h datum i representations. Macro transformers take syntax objects as input and return (expanded) syntax objects as output. Embedded within each syntax object is sufficient information to determine the bindings of all identifiers contained within the syntax object, along with an internal representation of the syntactic form itself. Other implementation-dependent information may be contained within a syntax object; for example, the position of the expression in the original source code may be included for debugging purposes....
View Full Document
- Fall '09
- Computer Science, Identifier, Hygienic macro, syntax-case