4 ms·
>and metaprogramming in D is much nicer, because it was designed from the ground up instead of the bug elevated to feature that metaprogramming is in C++ Yet n
by tzahola 9y ago
>and metaprogramming in D is much nicer, because it was designed from the ground up instead of the bug elevated to feature that metaprogramming is in C++
Yet neither of them are as elegant as LISP macros.
- deleted 9y ago[deleted]
- jordigh 9y agoVery true! I wish D's metaprogramming was slightly more structured instead of relying on raw string concatenation. However, it's not so bad, and it's miles ahead of C++ metaprogramming in terms of ease of use. It's nice that it's so much more deliberately conceived. There's static if, static for, compile-time function evaluation, template and string mixins, and more! I think D's metaprogramming is very close to lisp, possibly as close as possible without having sexps.
- beojan 9y ago> relying on raw string concatenation > it's not so bad You can always use the C preprocessor in C++ if raw string manipulation is enough. Seriously, though, constexpr means C++ also has static if, compile time loops, function eval, etc.
- jordigh 9y agoRaw string manipulation in D's mixins is much more limited than in CPP, and it's also not the only tool available for metaprogramming. https://dlang.org/mixin.html https://dlang.org/mixin.html > constexpr means C++ also has static if, compile time loops, function eval, etc. It's still not quite the same. I'm sorry to not bring examples, but if you look for them yourself, I think you'll find that D's metaprogramming looks nicer than C++'s constexpr.
- nicwilson 9y ago> C++ also has static if Not even close. You can't conditionally insert a member.
- bstamour 9y agoHopefully that will be fixed in a future C++ standard. There is an interesting static reflection proposal floating around that would allow for this, plus more.
- xaedes 9y agoThe talk about the reflection proposal was amazing. Meta classes are also very cool. We can only hope it comes fast. https://www.youtube.com/watch?v=4AfRAVcThyA https://www.youtube.com/watch?v=4AfRAVcThyA
- ChrisRackauckas 9y agoCompilation with LISP-like macros for fast generic programming? Julia?
- bachmeier 9y agoI'm not sure how you're measuring elegance, but writing Lisp macros and getting them to work correctly has never been something I'd call elegant. You have the Common Lisp approach, where you work in a complicated sublanguage like this example from PCL: (defmacro when (condition &rest body) `(if ,condition (progn ,@body))) and then you think hard about where the leaks are. Or else you take the Scheme approach of hygienic macros which are even less elegant. Macros in Lisp are powerful, but I'm not sure metaprogramming in Lisp is better than in a language like D.
- sedachv 9y ago> You have the Common Lisp approach, where you work in a complicated sublanguage like this example from PCL: I don't think you actually understand anything about the example code you posted. There is no special "complicated sublanguage" - the backquote[1] is an extension of the quote shorthand notation[2] for list literals. It is for building data structures and has nothing to do with "sublanguages" or macros. There is no special syntax for macros in Common Lisp. Common Lisp macros do not produce source code - they produce any type of Common Lisp objects directly. That is why they are simpler and strictly more powerful than D templates. When it comes to templates, I wouldn't call anything from this list of D examples[3] elegant. [1] http://www.lispworks.com/documentation/HyperSpec/Body/02_df.htm http://www.lispworks.com/documentation/HyperSpec/Body/02_df.... [2] http://www.lispworks.com/documentation/HyperSpec/Body/s_quote.htm http://www.lispworks.com/documentation/HyperSpec/Body/s_quot... [3] https://dlang.org/templates-revisited.html https://dlang.org/templates-revisited.html
- bachmeier 9y ago> I don't think you actually understand anything about the example code you posted. This doesn't add anything to the conversation. If you want to discuss my post, I'm happy to discuss. You're clearly upset that I didn't praise Common Lisp, but things like that don't lead to useful discussion. > There is no special "complicated sublanguage" - the backquote[1] is an extension of the quote shorthand notation[2] for list literals. It is for building data structures and has nothing to do with "sublanguages" or macros. There is no special syntax for macros in Common Lisp. I've never seen anyone write macros using only s-expressions. True, you don't need to learn any special syntax to do it, but that's not how anyone writes macros. > When it comes to templates, I wouldn't call anything from this list of D examples[3] elegant. How is that is relevant to my comment?