5 ms·
> The only language where macros aren't just C's #define to replace text. You're working directly with the AST It's hardly the only such language. In my experi
by thewakalix 5y ago
> The only language where macros aren't just C's #define to replace text. You're working directly with the AST
It's hardly the only such language. In my experience, Haskell, Rust, Common Lisp, and Scheme all have macros that operate by syntax trees rather than text substitution, and I have no doubt that there are several more that I'm not aware of.
- davidkunz 5y agoI add: Nim, Crystal
- adenozine 5y agoI add Io(defunct), Self, Smalltalk, Tcl...
- auxym 5y agoEh, Tcl's metaprogramming, as far as I remember, is highly text based. EIAS.
- jjnoakes 5y agoIt's mostly based on manipulating lists. Scoping is a bit odd, but if you squint, the fact that unevaluated lists are passed into functions where they can be manipulated (by normal tcl list functions) and then evaluated in the caller's scope (or in other scopes), coupled with the fact that built in syntax (if, proc, for, etc) is the same as user-defined function call syntax, gives you more metaprogramming power than you might expect.
- adenozine 5y agoTrue, mostly. As the other commenter noted, function calls can be squeezed through some rather macro-looking holes if you just push hard enough. Don't get me wrong, Tcl metaprogramming is awful and gross and I don't recommend it, I was just being the stereotypical nitpick HN commenter for that moment since it CAN be done.
- leephillips 5y agoJulia is another.
- gpderetta 5y agoIn fact, which language except C and derivatives has macros that are inky simple token replacement?
- linkdd 5y agoAFAIR, Haskell do have metaprogramming but not with macros, I remember reading this[0] a few months ago. Maybe I misread the article? For Rust, I've seen more usage of `macro_rules!` than the other one (so much I did not even know it existed). And it looks a lot like C's #define. But yeah, my bad, I've been a bit too presumptuous when saying Elixir was the only one. [0] - https://chrisdone.com/posts/haskell-doesnt-have-macros/
- pjmlp 5y agoAdding Java and .NET languages, which do it via attributes/annotations, compiler plugins, and T4 templates and code generators. Circle compiler for C++, and D as well.