# Macros [[Metaprogramming]] Macros are used to generate code at compile time. Simplistic macro systems like in [[C]]/[[C++]] use string replacement, while more refined work directly on the [[Abstract Syntax Tree]]. This is where a "homo-iconic" representation (see [[Homoiconicity]]), where the data structure of the AST is close to the syntax of the language, and the notation of the AST is close to the notation of the language, e.g. [[SEXP Representation]] comes in handy. That is why [[Common Lisp Macros]] are quite pleasant to write ([[ZK - Lisp metaprogramming provides IDE features]]). Issues with symbol leaks (unhygienic) are addressed for example in [[Scheme]] using [[Hygienic Macros]]. The approaches in [[Racket]] are very refreshing. Other systems that I haven't looked at yet are [[Template Haskell]] and [[Rust Macros]]. Researchers in the field are [[Laurence Tratt]]. ## Links To Read - [Laurence Tratt: When Are Macros Useful?](https://tratt.net/laurie/essays/entries/when_are_macros_useful.html) A long long article about all kinds of macros, ultimately getting into [[Rust]] Macros: - [How I Learned to Stop Worrying and Love Macros](https://zdimension.fr/how-i-learned-to-stop-worrying-and-love-macros/) ## Links A helper library to make [[Macros (Programming)]] writing in [[Common Lisp]] provide better [[Error Handling]]: - [GitHub - scymtym/trivial-with-current-source-form: Helps macro writers produce better errors for macro users](https://github.com/scymtym/trivial-with-current-source-form)