Skip to main content Accessibility help

Macros that Work Together: Compile-time bindings, partial expansion, and definition contexts


Racket is a large language that is built mostly within itself. Unlike the usual approach taken by non-Lisp languages, the self-hosting of Racket is not a matter of bootstrapping one implementation through a previous implementation, but instead a matter of building a tower of languages and libraries via macros. The upper layers of the tower include a class system, a component system, pedagogic variants of Scheme, a statically typed dialect of Scheme, and more. The demands of this language-construction effort require a macro system that is substantially more expressive than previous macro systems. In particular, while conventional Scheme macro systems handle stand-alone syntactic forms adequately, they provide weak support for macros that share information or macros that use existing syntactic forms in new contexts. This paper describes and models features of the Racket macro system, including support for general compile-time bindings, sub-form expansion and analysis, and environment management. The presentation assumes a basic familiarity with Lisp-style macros, and it takes for granted the need for macros that respect lexical scope. The model, however, strips away the pattern and template system that is normally associated with Scheme macros, isolating a core that is simpler, can support pattern and template forms themselves as macros, and generalizes naturally to Racket's other extensions.

Hide All
Bawden, A. & Rees, J (1988) Syntactic closures. In Proceedings of the Lisp and Functional Programming, July 25–27, Snowbird, UT, USA. Pittsburgh: ACM, pp. 8695.
Clinger, William D. (1991) Hygienic macros through explicit renaming. LISP Pointers 4 (4), 2528.
Clinger, C. & Rees, J. (1991) Macros that work. In Proceedings of ACM Symposium on Principles of Programming Languages. New York, NY: ACM, pp. 155162.
Dybvig, R. Kent, Friedman, Daniel P. & Haynes, Christopher T. (1988) Expansion-passing style: A general macro mechanism. LISP Symb. Comput. 1 (1), 5375.
Dybvig, R. Kent, Hieb, R. & Bruggeman, C. (1993) Syntactic abstraction in Scheme. LISP Symb. Comput. 5 (4), 295326.
Felleisen, M., Findler, R. B. & Flatt, M. (2009) Semantics Engineering with PLT Redex. Cambridge, MA: MIT Press.
Fisher, D. & Shivers, O (2008) Building language towers with Ziggurat. J. Funct. Program. 18 (5–6), 707780.
Flatt, M. (2002) Compilable and composable macros, you want it when? In Proceedings of the Seventh ACM SIGPLAN International Conference on Functional Programming (ICFP 2002), Pittsburgh, PA, USA, October 4–6, pp. 7283.
Gabbay, M. & Pitts, A. (1999) A new approach to abstract syntax involving binders. In the Proceedings of the 14th IEEE Symposium on Logic in Computer Science (LICS'99), Trento, Italy, pp. 341363.
Gasbichler, M. (2006) Fully-Parameterized Higher-Order Modules with Hygienic Macros. PhD dissertation, Universität Tübingen, Tübingen, Germany.
Ghuloum, A. & Dybvig, R. Kent (2007) Portable syntax-case. Accessed April, 2012. Available at:
Herman, D. (2010) A Theory of Typed Hygienic Macros. PhD dissertation, Northeastern University, Boston, Massachusetts.
Hilsdale, E. & Friedman, D. P. (2000) Writing macros in continuation-passing style. Proceedings of the Workshop on Scheme and Functional Programming, Montreal, September 17.
Kohlbecker, E. Eugene, Friedman, Daniel P, Felleisen, M. & Duba, B. (1986) Hygienic macro expansion. In Proceedings of the ACM Conference on Lisp and Functional Programming. New York, NY: ACM, pp. 151181.
Kohlbecker, E. Eugene & Wand, M. (1987) Macro-by-example: Deriving syntactic transformations from their specifications. In Proceedings of the 14th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, Munich, Germany, January 2123, pp. 7784.
Milner, R., Tofte, M. & Harper, R. (1990) The Definition of Standard ML. Cambridge, MA: MIT Press.
Pfenning, F. & Elliott, C. (1988) Higher-order abstract syntax. In Proceedings of the SIGPLAN '88 Conference on Programming Language Design and Implementation. New York, NY: ACM, pp. 199208.
Pfenning, F. & Schürmann, C. (1999) System description: Twelf – a meta-logical framework for deductive systems. In Proceedings of the International Conference on Automated Deduction, Trento, Italy, pp. 202206.
Sheard, T. & Peyton Jones, S. (2002) Template meta-programming for Haskell. In Proceedings of Haskell Workshop 2002, Pittsburgh, PA, USA, pp. 6075.
Shinwell, Mark R., Pitts, A. M. & Gabbay, M. J. (2003) FreshML: Programming with binders made simple. In Proceedings of the 8th ACM International Conference on Functional Programming. New York, NY: ACM, pp. 263274.
Sperber, M. (Ed.) (2009) Revised 6 report on the algorithmic language Scheme. J. Funct. Program. 19(supplement), 1301.
Van Tonder, A. (2007) R6RS libraries and macros. Accessed April, 2012. Available at:
Van Wyk, E., Bodin, D., Krishnan, L. & Gao, J. (2009) Silver: an extensible attribute grammar system. Sci. Comput. Program. 75 (1–2) doi: 10.1016/j.scico.2009.07.004
Waddell, O. & Dybvig, R. Kent (1999) Extending the scope of syntactic abstraction. In Proceedings of ACM Symposium on the Principles of Programming Languages. New York, NY: ACM, pp. 203213.
Recommend this journal

Email your librarian or administrator to recommend adding this journal to your organisation's collection.

Journal of Functional Programming
  • ISSN: 0956-7968
  • EISSN: 1469-7653
  • URL: /core/journals/journal-of-functional-programming
Please enter your name
Please enter a valid email address
Who would you like to send this to? *


Full text views

Total number of HTML views: 0
Total number of PDF views: 0 *
Loading metrics...

Abstract views

Total abstract views: 0 *
Loading metrics...

* Views captured on Cambridge Core between <date>. This data will be updated every 24 hours.

Usage data cannot currently be displayed

Macros that Work Together: Compile-time bindings, partial expansion, and definition contexts

Submit a response


No Discussions have been published for this article.


Reply to: Submit a response

Your details

Conflicting interests

Do you have any conflicting interests? *