4 ms·
Well C macros work at the text-level, Rust macros run at the AST level (but not the type level, that is you cannot construct syntactically incorrect stuff but y
by navaati 9y ago
Well C macros work at the text-level, Rust macros run at the AST level (but not the type level, that is you cannot construct syntactically incorrect stuff but you can construct wrong-typed stuff).
So I don't really know lisp macros but I guess it's still closer than to C.
- foldr 9y agoRust macros actually work more at the token level than at the AST level.
- navaati 9y agoOh I see, thx !
- RReverser 9y agoThey work on both - for example, if you specify $expr:expr, it will actually parse it as an expression node and won't allow to simply pass it into another macro as $pat:pat because of AST node type mismatch even if actual tokens are still compatible.
- foldr 9y agoThat's a good point. What I was trying to get at is that Rust macros don't let you manipulate ASTs in any straightforward way. So they are not best thought of as AST -> AST transforms.
- kibwen 9y agoRust macros are Scheme macros, there's no similarity to C.