Ruby Macros
summary
A working Ruby macro system is presented that manipulates syntax trees at parse time and inlines code: macro runs at parse time, accepts arguments as S‑expressions, and returns parse trees that are spliced into callers. Implementations shown include an assert macro that inspects source to produce better error messages, a loop unroller and an inline-method transformation; a custom parser (redparse) produces object‑oriented trees but is slow, macros are global and unhygienic, require a special require and currently target Ruby 1.8—functional but with startup and scoping limits.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 0:38C Macros
- 1:15List Macros
- 1:50Macros
- 3:37S Expressions
- 4:40Arguments
- 5:31Forms
- 6:26Tree
- 7:42Form Escape
- 9:15debug
- 17:11red parse
- 20:01macro issues
- 23:41loop unrolling
- 24:51inline macro
related talks
52mTreetop: Syntactic Analysis with Ruby
40mTechniques for Metaprogramming in Erlang
43mGrammars, Parsers, and Interpreters, In Ruby
51mForbidden Fruit: A Test of Ruby's Parse Tree
31mSeeing Metaprogramming and Lambda Function Patterns in Ruby
33mRuby: A Family History
34mHijacking Ruby Syntax in Ruby
36mMetaprogramming? Not good enough!
