R lets you do macro-ish things at at runtime [1], and `.` is a valid variable name [2]. so %>% can just evaluate the AST of its right argument in an environment with `. = a`.
(it's probably a bit more involved because %>% also supports
a %>% f(b) === f(a, b)
in which case %>% has to do some AST surgery to splice another argument in front of `b`.)
Comments
Tidyr/dplyr (R) can do something very close to this but I don't know how it is achieved. There it is a dot
(it's probably a bit more involved because %>% also supports
in which case %>% has to do some AST surgery to splice another argument in front of `b`.)---
[1] https://en.wikipedia.org/wiki/Fexpr
[2] think `_` in python etc. R uses dots instead of underscores