Smooth transition to D2 for Tango users?
Denis Koroskin
2korden at gmail.com
Mon Sep 22 15:22:58 PDT 2008
On Tue, 23 Sep 2008 02:00:36 +0400, Steven Schveighoffer
<schveiguy at yahoo.com> wrote:
>
> "Sergey Gromov" wrote
>> Bruce Adams <tortoise_74 at yeah.who.co.uk> wrote:
>>> I don't think its unreasonable to expect that braces will be balanced
>>> in all future versions of the language.
>>
>> Braces can be in strings or comments. It's quite likely to have braces
>> in strings in many kinds of parser programs.
>>
>> If you want code hidden from a compiler, put it in a string and mix in.
>>
>> enum veryD2Code = `
>> auto foo(T)(T x) if (__traits(hasMember, "opCall"))
>> {
>> return x();
>> }
>> `;
>>
>> version (D_Version2)
>> {
>> mixin(veryD2Code);
>> }
>>
>> In D2 you can use token strings for that purpose, so that the code will
>> even be highlighted in your editor, but will not interfere with the
>> compiler.
>
> oops, D1 doesn't support that type of enum ;)
>
> If the problem can't be solved with the current compilers, then the
> solution
> provided to make it work should be easy to use. I don't see this type of
> solution as easy to use, nor the 'version(D2)' type of solution. What if
> you have const member functions? If we had a preprocessor...
We do have some kind of it:
#!/usr/bin/dmd -run
#line 42 "foo.d"
#pragma(msg, "bar");
...
C# has also support for the following "preprocessor" directives (although
it doesn't have a preprocessor):
#if
#else
#elif
#endif
#warning
#error
#line
#region
#endregion
#define
#undef
These are widely known and understandable to many programmers, so D could
extend the preprocessor directives list with some of them.
An import point is that unlike C and C++, you cannot use these directives
to create macros!
D ought to have a way to mark some section of code so that it won't get
parsed and semantically analyzed. Balancing of the curly braces is one of
the solutions:
version (Dv2) {
const int f()
} else {
int f()
}
#if/#else/#elif/#endif is another, also a good one:
>
> #ifdef Dv2
> const int f()
> #else
> int f()
> #endif
>
More information about the Digitalmars-d
mailing list