November 15, 2006
Georg Wrede schrieb:

> In the long run, I think there are few non-trivial template application areas where it wouldn't play a role.

Would be nice to see something concrete.
Björn
November 15, 2006
Walter Bright wrote:
> http://www.digitalmars.com/d/tuple.html

The one thing I didn't get was why there was two versions of the "Curry" template, one with a "Dummy" parameter.  Can you explain?  And then can you post the explanation on that page?

Russ
November 15, 2006
On Wed, 15 Nov 2006 10:11:04 -0800, Bill Baxter <wbaxter@gmail.com> wrote:

> Don Clugston wrote:
>
>> Normal C code reduces in size by ~20%  when converted to D. But what happens to LOC when complex C++ template code is converted to D??? That's frightening. <g>
>
> We'll have all of boost on the back of a napkin before you know it!
>
> --bb


Its scary! D Templates have certainly come a long way!  Congrats, Walter.  A fine job.

-JJR
November 16, 2006
Russ Lewis wrote:
> Walter Bright wrote:
>> http://www.digitalmars.com/d/tuple.html
> 
> The one thing I didn't get was why there was two versions of the "Curry" template, one with a "Dummy" parameter.  Can you explain?  And then can you post the explanation on that page?

It's because you cannot overload two templates with the same parameter list. So we make them different by giving one a dummy parameter.
November 16, 2006
Walter Bright wrote:
> Russ Lewis wrote:
>> Walter Bright wrote:
>>> http://www.digitalmars.com/d/tuple.html
>>
>> The one thing I didn't get was why there was two versions of the "Curry" template, one with a "Dummy" parameter.  Can you explain?  And then can you post the explanation on that page?
> 
> It's because you cannot overload two templates with the same parameter list. So we make them different by giving one a dummy parameter.

Just to be clear, this limitation will eventually go away, correct?


Sean
November 16, 2006
Sean Kelly wrote:
> Walter Bright wrote:
>> Russ Lewis wrote:
>>> Walter Bright wrote:
>>>> http://www.digitalmars.com/d/tuple.html
>>>
>>> The one thing I didn't get was why there was two versions of the "Curry" template, one with a "Dummy" parameter.  Can you explain?  And then can you post the explanation on that page?
>>
>> It's because you cannot overload two templates with the same parameter list. So we make them different by giving one a dummy parameter.
> 
> Just to be clear, this limitation will eventually go away, correct?

Maybe.
November 16, 2006
Chris Miller wrote:
> On Wed, 15 Nov 2006 07:53:11 -0500, Bill Baxter <wbaxter@gmail.com> wrote:
> 
>> Seeing this:
>>
>>    alias Tuple!(TP, 8) TR;  // TR is now float,float,3,8
>>    alias Tuple!(TP, TP) TS; // TS is float,float,3,float,float,3
>>
>> makes me really wish the syntax for typedef/alias were:
>>
>>    alias newname = oldname;
>>
>> I always thought the ordering for C++'s typedef was goofy.  I get it backwards about half the time I think, just because it's basically an assignment perversely written the other way around from all other assignments.
>>
>> --bb
> 
> Think of a variable declaration and then put alias/typedef on front of it; ever since I thought of it like this I never made the mistake again.
> 
>    int foo;  // new foo
>    typedef int foo;  // new foo

You probably got the point, but what I meant was that types in D are really starting to look just like compile-time variables in a compile-time metaprogramming language.  Since they have such a strong connection with runtime variables used in D's runtime language, it would be nice if the syntax for assigning to those compile-time type variables reflected that similarity, instead of clinging to the syntax chosen in the 70's by Mr. Ritchie before any of this was even dreamed of.

As far as my messing up the order, I think the big problem is just that it's opposite to the order of my thinking.  My thought process is usually something like
1) I need to use the type of a slot here.
2) Ugh, what was that type exactly? U delgate(T) or S delegate(U,V)?
3) It would be handy to have a slot_t alias to represent that.
4) ok, I'll make one: [/me types 'alias   slot_t;']
5) *then* I go searching around to figure out what the actual type is to fill in there.

So I usually end up /writing/ it in the order  'alias', newname, oldname regardless of the order it appears on the screen.

--bb
November 16, 2006
Walter Bright wrote:
> Sean Kelly wrote:
>> Walter Bright wrote:
>>> Russ Lewis wrote:
>>>> Walter Bright wrote:
>>>>> http://www.digitalmars.com/d/tuple.html
>>>>
>>>> The one thing I didn't get was why there was two versions of the "Curry" template, one with a "Dummy" parameter.  Can you explain?  And then can you post the explanation on that page?
>>>
>>> It's because you cannot overload two templates with the same parameter list. So we make them different by giving one a dummy parameter.
>>
>> Just to be clear, this limitation will eventually go away, correct?
> 
> Maybe.

Ack! Related question :-)  I assume this will work at some point?:

  T fn( T, U )( U val )
  {
      return T.init;
  }

  void main()
  {
      int i = fn!(int)( 1.0 );
  }

Currently, I get:

  test.d(9): template instance fn!(int) does not match any template declaration
  test.d(9): Error: template instance 'fn!(int)' is not a variable
  test.d(9): Error: function expected before (), not fn!(int) of type int


Sean
November 16, 2006
Walter Bright wrote:
> Don Clugston wrote:
>> Walter Bright wrote:
>>> http://www.digitalmars.com/d/tuple.html
>>
>> "A tuple is a sequence of elements. Those elements can be types, expressions, or aliases."
>>
>> Is this wording correct? How can you make an alias tuple?
> 
> Just pass in symbols as template arguments to a U...

Awesome! This is even better than I thought.
One problem -- it seems that if the tuple has a mix of types and instances, you can't index it.
-------------
struct S { int x; long y; }

template Tuple(E...)
{
    alias E Tuple;
}

void main()
{
    int q;

    alias Tuple!(S, q) Z;
    alias Z[0] R; // fails -- "tuple E is used as a type"
}
-------------
Also, is there any way to get .tupleof to return an alias tuple?
For example, you can't write
alias S.tupleof[0] R;

Nor (more importantly) can you pass it as an template alias parameter:

template Z(alias W) {
    const int Z = 2;
}

const int x = Z!((S.tupleof[0]));

(If it worked, I could write a dump!(X) which would display all the names of the members of X, with their values...).
November 16, 2006
Sean Kelly wrote:
> Ack! Related question :-)  I assume this will work at some point?:
> 
>   T fn( T, U )( U val )
>   {
>       return T.init;
>   }
> 
>   void main()
>   {
>       int i = fn!(int)( 1.0 );
>   }
> 
> Currently, I get:
> 
>   test.d(9): template instance fn!(int) does not match any template declaration
>   test.d(9): Error: template instance 'fn!(int)' is not a variable
>   test.d(9): Error: function expected before (), not fn!(int) of type int

That's a hard one to get to work, as it has chicken-and-egg problems.