Abstract
Hygienic macro systems, such as Scheme’s, automatically rename variables to prevent unintentional variable capture—in short, they “just work.” Yet hygiene has never been formally presented as a specification rather than an algorithm. According to folklore, the definition of hygienic macro expansion hinges on the preservation of alpha-equivalence. But the only known notion of alpha-equivalence for programs with macros depends on the results of macro expansion! We break this circularity by introducing explicit binding specifications into the syntax of macro definitions, permitting a definition of alpha-equivalence independent of expansion. We define a semantics for a first-order subset of Scheme-like macros and prove hygiene as a consequence of confluence.
Chapter PDF
Similar content being viewed by others
Keywords
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.
References
Kiselyov, O.: How to write seemingly unhygienic and referentially opaque macros with syntax-rules. In: Scheme Workshop (2002)
Kohlbecker, E., Friedman, D.P., Felleisen, M., Duba, B.: Hygienic macro expansion. In: LISP and Functional Programming (1986)
Clinger, W., Rees, J.: Macros that work. In: POPL (1991)
Bawden, A., Rees, J.: Syntactic closures. In: LISP and Functional Programming, pp. 86–95 (1988)
Kent Dybvig, R., Bruggeman, C.: Syntactic abstraction in Scheme. Lisp and Symbolic Computation 5(4), 295–326 (1993)
van Tonder, A.: SRFI 72: Hygienic macros. Online (September 2005)
Clinger, W., Rees, J.: Revised4 report on the algorithmic language Scheme. Technical report (1991)
Culpepper, R., Felleisen, M.: Taming macros. In: Karsai, G., Visser, E. (eds.) GPCE 2004. LNCS, vol. 3286, Springer, Heidelberg (2004)
Gabbay, M.J., Pitts, A.M.: A new approach to abstract syntax with variable binding. Formal Aspects of Computing 13(3–5), 341–363 (2001)
Gorn, S.: Explicit definitions and linguistic dominoes. In: Systems and Computer Science, Proceedings of the Conference held at Univ. of Western Ontario (1967)
Barendregt, H.P.: The Lambda Calculus: Its Syntax and Semantics. revised edn. North-Holland, Amsterdam (1984)
Wright, A.K., Felleisen, M.: A syntactic approach to type soundness. Information and Computation 115(1), 38–94 (1994)
Flatt, M.: PLT MzScheme: Language manual. Technical Report PLT-TR2007-1-v371, PLT Scheme Inc. (2007), http://www.plt-scheme.org/techreports/
Krishnamurthi, S.: Linguistic Reuse. PhD thesis, Rice University (May 2001)
de Rauglaudre, D.: Camlp4 reference manual. Online (September 2003)
Sheard, T., Peyton Jones, S.: Template metaprogramming for Haskell. In: Chakravarty, M.M.T. (ed.) Haskell Workshop, pp. 1–16 (2002)
Ganz, S.E., Sabry, A., Taha, W.: Macros as multi-stage computations: Type-safe, generative, binding macros in MacroML. In: ICFP 2001, pp. 74–85 (2001)
Taha, W., Johann, P.: Staged notational definitions. In: Pfenning, F., Smaragdakis, Y. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 97–116. Springer, Heidelberg (2003)
Gasbichler, M.: Fully-parameterized, first-class modules with hygienic macros. PhD thesis, University of Tübingen (August 2006)
Griffin, T.: Notational definition—a formal account. In: LICS 1988, pp. 372–383 (1988)
Bove, A., Arbilla, L.: A confluent calculus of macro expansion and evaluation. In: LISP and Functional Programming, pp. 278–287. ACM Press, New York (1992)
McKinna, J., Pollack, R.: Some lambda calculus and type theory formalized. Journal of Automated Reasoning 23, 373–409 (1999)
Gordon, A.D.: A mechanisation of name-carrying syntax up to alpha-conversion. In: Workshop on HOL Theorem Proving and its Applications, pp. 413–425 (1994)
McBride, C., McKinna, J.: Functional pearl: I am not a number—I am a free variable. In: Haskell Workshop, pp. 1–9 (2004)
Kohlbecker, E.E., Wand, M.: Macro-by-example: Deriving syntactic transformations from their specifications. In: Principles of Programming Languages (1987)
Author information
Authors and Affiliations
Editor information
Rights and permissions
Copyright information
© 2008 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Herman, D., Wand, M. (2008). A Theory of Hygienic Macros. In: Drossopoulou, S. (eds) Programming Languages and Systems. ESOP 2008. Lecture Notes in Computer Science, vol 4960. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-78739-6_4
Download citation
DOI: https://doi.org/10.1007/978-3-540-78739-6_4
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-78738-9
Online ISBN: 978-3-540-78739-6
eBook Packages: Computer ScienceComputer Science (R0)