Lecture 18
Macros
Programming Languages
UW CSE 341 - Spring 2021
Macros
Macro expansion
Racket Macros
Example Uses
When Should We Use Macros?
Three Questions + Macro Mechanics
Question 1: How to Tokenize?
Question 2: How to parenthesize (associativity)?
Question 3: How to interact with scope?
Example Racket Macro Definitions
Revisiting Promises
Defining our own macro for delay
Should force also be a macro? NO!
Another BAD macro
Be careful when copying syntax!
Local variables in macros? What about shadowing?!
Shadowing “the other way”
Hygiene
More examples
See the code for a few more examples of Racket macros: