Towards the Essence of Hygiene

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.

[1]  R. Kent Dybvig,et al.  Revised6 Report on the Algorithmic Language Scheme , 2009 .

[2]  R. Kent Dybvig,et al.  Syntactic Abstraction: The syntax-case expander , 2007 .

[3]  Matthias Felleisen,et al.  Hygienic macro expansion , 1986, LFP '86.

[4]  Matthias Felleisen,et al.  Well-Shaped Macros , 2003 .

[5]  Matthew Flatt,et al.  Keeping it Clean with Syntax Parameters , 2011 .

[6]  Matthias Felleisen,et al.  Fortifying macros , 2010, ICFP '10.

[7]  Jonathan Rees,et al.  Syntactic closures , 1988, LISP and Functional Programming.

[8]  Matthias Felleisen,et al.  Taming Macros , 2004, GPCE.

[9]  Andrew M. Pitts,et al.  A New Approach to Abstract Syntax with Variable Binding , 2002, Formal Aspects of Computing.

[10]  Jonathan Rees,et al.  Macros that work , 1991, POPL '91.

[11]  Mitchell Wand,et al.  Macro-by-example: Deriving syntactic transformations from their specifications , 1987, POPL '87.

[12]  Mitchell Wand,et al.  A Theory of Hygienic Macros , 2008, ESOP.

[13]  Torben Amtoft,et al.  Faithful Translations between Polyvariant Flows and Polymorphic Types , 2000, ESOP.

[14]  Tauno Kekäle,et al.  Beautiful Code. Leading Programmers Explain How They Think , 2009 .

[15]  Robert Hieb,et al.  Syntactic abstraction in scheme , 1992, LISP Symb. Comput..

[16]  David Herman,et al.  A theory of typed hygienic macros , 2010 .

[17]  Amr Sabry,et al.  Macros as multi-stage computations: type-safe, generative, binding macros in MacroML , 2001, ICFP '01.

[18]  William Clinger Hygienic macros through explicit renaming , 1991, LIPO.