Unification and extension of compile-time reflection

Marcin Kuszczak aarti_please_no at spam_interia.pl
Tue Nov 25 15:01:52 PST 2008


Jarrett Billingsley wrote:

> On Tue, Nov 25, 2008 at 3:56 AM, Aarti_pl <aarti at interia.pl> wrote:
>> I completely agree that compile time introspection in D is very messy.
>>
>> There are some other problems with CT introspection, which I have
>> explained in my post some time ago:
>> http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=77654
>>
>> In the same post I also proposed unified syntax for template
>> specialization, static if, static assert and alias, while dropping
>> completely is() expression for templates. Basically my proposal is about
>> extending template pattern matching.
>>
>> You have touched few other areas which needs to be rethought. But I think
>> that just using traits will not work very good. It will be too explicit
>> e.g.
>>
>> Your proposal:
>> static if(is(traits(isAssociativeArray, T))) {
>>  traits(associativeArrayKeyType, K);
>>  traits(associativeArrayValueType, V);
>> }
>>
>> Compared to my proposal:
>> static if (T V K : V[K]) {
>>  //V and K is already defined here
>> }
>>
>> Anyway merging these two proposals will improve situation significantly.
> 
> Ahh, nonono, I proposed keeping is() but only as syntactic sugar for
> traits() magic.  So under my proposal one would be able to do:
> 
> static if(is(T : V[K], K, V))
> {
>    // V and K are defined here
> }

You are the second victim of strange D is expression syntax. If it does help you the first was probably Andrei on this newsgroup :-)
(http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=77727)

Above, given by you, example is incorrect and does not compile. The proper syntax for querying of types for associative arrays is, so strange that probably nobody can use it without looking into documentation.

Below is proper syntax, which works with DMD 2.021:

Please notice that 'V' is before '==', but 'K' is after pattern matching expression (sic!). One type is used before declaration, but the second one after !

void main() {
     alias long[char[]] T;
     static if (is(T V == V[K], K)) {
         pragma(msg, V.stringof ~ " " ~ K.stringof);
     } else static if (is(T V == V[])) {
         pragma(msg, V.stringof);
     }
 }

> Except that it would just be _implemented_ using traits.  :)

>> BTW. I also hate underscores in keywords. :-P
> 
> They are the devil!

Please notice that my proposal is not directly connected with your's, but anyway it still concerns the same subject: D templates syntax should be rethought and redesigned, because currently there is a lot of mess. (Yes, yes - I know that it is still much better than in C++ :-)) ).

-- 
Regards
Marcin Kuszczak (Aarti_pl)
-------------------------------------
Ask me why I believe in Jesus - http://www.zapytajmnie.com (en/pl)
Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/
-------------------------------------



More information about the Digitalmars-d mailing list