-
-
Notifications
You must be signed in to change notification settings - Fork 610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 6207 - Mixin template evaluated to string can convert to string mixin expression implicitly #459
Conversation
|
First, thanks Kenji for your tireless work on fixing DMD bugs and filling little language holes. However, contrary to many of your other fixes, I don't think this pull request is a change to the better: Yes, string mixins and mixin templates in D are limited in the sense that you explicitly need to »embed« them using void main() {
auto a = "some funky value";
foo(3);
}you can be sure that the invocation of Your proposal would break this fundamental guarantees about the semantics of D code, and in my opinion, we should not allow developers to open this Pandora's box. After all, this kind of uncontrollable semantics is one of the reasons why preprocessor macros are generally avoided in C++ if possible. If you want, I can put together a more detailed account on why I think this would not be a wise addition to the language, but right now, I'm really curious what possible applications for the feature you have been thinking of – besides introducing template access to the instantiation scope »though the back door«. |
This feature is supposed to work only if given an explicit template arguments. In the example,
In addition, this feature generates just only an expression as a result of string mixin. Please see the following example. mixin template Inj(string s) { enum Inj = s; }
void func() {}
void main()
{
// Inj!("auto a = 10;"); // NG, cannot inject statement/declaration.
Inj!("func()"); // OK, `func()` is expression.
}Yes, I acknowledge that it can be used as a macro. But I think it is useful for DSL, and enough hygienic to accept it. |
|
I share Klickverbot's reservations about this. It's a major change, and I fear it may blow up in our faces. |
… mixin expression implicitly If mixin template instantiation makes manifest constant string and it appears in expression context, the compiler converts it implicitly to string mixin expression.
|
I think this work is pertinent barring some issues. Today if anyone writes or sees sees One aspect of hygiene is that arbitrary stuff from the context may be caught. For example, writing Another aspect is that the mixin may define its own symbol, which would spill into the enclosing scope. But wait, an expression can't introduce symbols, so that's taken care of by design. Nice. The last aspect is integrating these mixin subexpressions into larger expressions. Consider e.g. int a, b;
auto x = func!("a + b")() * c;How does the expansion occur? Would that be To summarize: I think this has its uses but we need to really think it through. For example, more use cases would be great. I mentioned string interpolation. What are others? |
Improve documentation in std.stdio
|
This enhancement will not be merged in the near future, so I close it. |
http://d.puremagic.com/issues/show_bug.cgi?id=6207
If mixin template instantiation makes manifest constant string and it appears in expression context, the compiler converts it implicitly to string mixin expression.