View mode: basic / threaded / horizontal-split · Log in · Help
November 25, 2008
Re: Unification and extension of compile-time reflection
"Bill Baxter" <wbaxter@gmail.com> wrote in message 
news:mailman.57.1227650204.22690.digitalmars-d@puremagic.com...
> On Tue, Nov 25, 2008 at 10:42 PM, Steven Schveighoffer
> <schveiguy@yahoo.com> wrote:
>> There is also one other benefit to min and max (and others) being first
>> class properties.  You can mimic their behavior in user-defined types. 
>> For
>> example, if int.min is changed to traits(min, int) or even 
>> int.traits.min,
>> then how do I define a similar 'minimum' for say, a time type, which 
>> would
>> be totally arbitrary.
>
> Agreed.  Clearly we need a way to define custom traits info, too.  It
> could be done using some kind of  traits{...} block in a class, that
> contains only functions and members safe for compile use.
>

[min=4, serializable]
class Foo {...}
November 25, 2008
Re: Unification and extension of compile-time reflection
Jarrett Billingsley wrote:

> On Tue, Nov 25, 2008 at 3:56 AM, Aarti_pl <aarti@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/
-------------------------------------
November 25, 2008
Re: Unification and extension of compile-time reflection
Nick Sabalausky wrote:

> 
> "Jarrett Billingsley" <jarrett.billingsley@gmail.com> wrote in message
>>
>> 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
>> }
>>
> 
> I think his "eliminate is()" proposal was about turning the above into
> something like this:
> 
> static if(T : V[K], K, V)
> 
> instead of eliminating what is() does.

Almost exactly like you said, but also with reverted position of introduced types, so that declaration will be before usage. 

So instead of *current* syntax (in Jarret's example is syntax error):
static if(is(T V : V[K], K))

you could just use:
static if(T V K : V[K])

Looks simpler to me :-)

-- 
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/
-------------------------------------
November 26, 2008
Re: Unification and extension of compile-time reflection
Ary Borenszweig wrote:
> I think that's an alias of an expression, and you can't do that. I was 
> thinking maybe something.traits returns an instance of an object that is 
> very well defined, but is only available at compile-time. So:

If Walter puts forth the effort to create this, very little further 
effort would make it available at runtime, most likely.

It'd be extremely convenient, though.
Next ›   Last »
1 2 3
Top | Discussion index | About this forum | D home