Abstract
Hygiene is an essential aspect of Scheme's macro system that prevents unintended variable capture. However, previous work on hygiene has focused on algorithmic implementation rather than precise, mathematical definition of what constitutes hygiene. This is in stark contrast with lexical scope, alpha-equivalence and capture-avoiding substitution, which also deal with preventing unintended variable capture but have widely applicable and well-understood mathematical definitions.
This paper presents such a precise, mathematical definition of hygiene. It reviews various kinds of hygiene violation and presents examples of how they occur. From these examples, we develop a practical algorithm for hygienic macro expansion. We then present algorithm-independent, mathematical criteria for whether a macro expansion algorithm is hygienic. This characterization corresponds closely to existing hygiene algorithms and sheds light on aspects of hygiene that are usually overlooked in informal definitions.
Supplemental Material
- Eli Barzilay, Ryan Culpepper, and Matthew Flatt. Keeping it clean with syntax parameters. In phProceedings of the Twelfth Workshop on Scheme and Functional Programming, October 2011.Google Scholar
- Alan Bawden and Jonathan Rees. Syntactic closures. In phProceedings of the 1988 ACM Conference on LISP and Functional Programming, LFP '88, pages 86--95, New York, NY, USA, 1988. ACM. ISBN 0--89791--273-X. 10.1145/62678.62687. Google Scholar
Digital Library
- William Clinger. Hygienic macros through explicit renaming. phACM SIGPLAN Lisp Pointers, IV (4): 25--28, October 1991. ISSN 1045--3563. 10.1145/1317265.1317269. Google Scholar
Digital Library
- William Clinger and Jonathan Rees. Macros that work. In phProceedings of the 18th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL '91, pages 155--162, New York, NY, USA, 1991. ACM. ISBN 0--89791--419--8. 10.1145/99583.99607. Google Scholar
Digital Library
- Ryan Culpepper. Fortifying macros. phJournal of Functional Programming, 22 (Special Issue 4--5): 439--476, September 2012. ISSN 1469--7653. 10.1017/S0956796812000275. Google Scholar
Digital Library
- Ryan Culpepper and Matthias Felleisen. Well-shaped macros. In phProceedings of the Fourth Workshop on Scheme and Functional Programming, pages 59--68, November 2003.Google Scholar
- Ryan Culpepper and Matthias Felleisen. Taming macros. In Gabor Karsai and Eelco Visser, editors, phGenerative Programming and Component Engineering, volume 3286 of phLecture Notes in Computer Science, pages 225--243. Springer Berlin Heidelberg, 2004. ISBN 978--3--540--23580--4. 10.1007/978--3--540--30175--2_12.Google Scholar
- Ryan Culpepper and Matthias Felleisen. Fortifying macros. In phProceedings of the 15th ACM SIGPLAN International Conference on Functional Programming, ICFP '10, pages 235--246, New York, NY, USA, 2010. ACM. ISBN 978--1--60558--794--3. 10.1145/1863543.1863577. Google Scholar
Digital Library
- R. Kent Dybvig. Syntactic abstraction: Thecodesyntax-case expander. In Andy Oram and Greg Wilson, editors, phBeautiful Code: Leading Programmers Explain How They Think, Theory in Practice, chapter 25. O'Reilly Media, July 2007. ISBN 978-0--596--51004--6.Google Scholar
- R. Kent Dybvig, Robert Hieb, and Carl Bruggeman. Syntactic abstraction in Scheme. phLISP and Symbolic Computation, 5 (4): 295--326, December 1993. ISSN 0892--4635 (Print) 1573-0557 (Online). 10.1007/BF01806308. Google Scholar
Digital Library
- Murdoch J. Gabbay and Andrew M. Pitts. A new approach to abstract syntax with variable binding. phFormal Aspects of Computing, 13 (3--5): 341--363, July 2002. ISSN 0934--5043 (Print) 1433--299X (Online). 10.1007/s001650200016.Google Scholar
- Steven E. Ganz, Amr Sabry, and Walid Taha. Macros as multi-stage computations: type-safe, generative, binding macros in MacroML. In phProceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming, ICFP '01, pages 74--85, New York, NY, USA, 2001. ACM. ISBN 1--58113--415-0. 10.1145/507635.507646. Google Scholar
Digital Library
- David Herman. phA Theory of Typed Hygienic Macros. PhD thesis, Northeastern University, Boston, MA, USA, May 2010. Google Scholar
Digital Library
- David Herman and Mitchell Wand. A theory of hygienic macros. In Sophia Drossopoulou, editor, phProgramming Languages and Systems, volume 4960 of phLecture Notes in Computer Science, pages 48--62. Springer Berlin Heidelberg, 2008. ISBN 978--3--540--78738--9. 10.1007/978--3--540--78739--6_4. Google Scholar
Digital Library
- Eugene Kohlbecker, Daniel P. Friedman, Matthias Felleisen, and Bruce Duba. Hygienic macro expansion. In phProceedings of the 1986 ACM Conference on LISP and Functional Programming, LFP '86, pages 151--161, New York, NY, USA, 1986. ACM. ISBN 0--89791--200--4. 10.1145/319838.319859. Google Scholar
Digital Library
- Eugene E. Kohlbecker and Mitchell Wand. Macro-by-example: Deriving syntactic transformations from their specifications. In phProceedings of the 14th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, POPL '87, pages 77--84, New York, NY, USA, 1987. ACM. ISBN 0--89791--215--2. 10.1145/41625.41632. Google Scholar
Digital Library
- Michael Sperber, R. Kent Dybvig, Matthew Flatt, and Anton van Straaten (eds.). Revised$^6$ report on the algorithmic language Scheme, September 2007. URL http://www.r6rs.org/. Google Scholar
Digital Library
- Michael Sperber, R. Kent Dybvig, Matthew Flatt, Anton van Straaten, Robby Findler, and Jacob Matthews. Revised\textsuperscript6 report on the algorithmic language Scheme. phJournal of Functional Programming, 19 (Supplement S1): 1--301, August 2009. ISSN 1469--7653. 10.1017/S0956796809990074. Google Scholar
Digital Library
- André van Tonder. phSRFI-72: Hygienic macros, September 2005. URL http://srfi.schemers.org/srfi-72/srfi-72.html.Google Scholar
Index Terms
Towards the Essence of Hygiene
Recommendations
Hygienic macro technology
The fully parenthesized Cambridge Polish syntax of Lisp, originally regarded as a temporary expedient to be replaced by more conventional syntax, possesses a peculiar virtue: A read procedure can parse it without knowing the syntax of any expressions, ...
Dependent type systems as macros
We present Turnstile+, a high-level, macros-based metaDSL for building dependently typed languages.
With it, programmers may rapidly prototype and iterate on the design of new dependently typed features and extensions.
Or they may create entirely ...
RustBelt: securing the foundations of the Rust programming language
Rust is a new systems programming language that promises to overcome the seemingly fundamental tradeoff between high-level safety guarantees and low-level control over resource management. Unfortunately, none of Rust's safety claims have been formally ...







Comments