November 30, 2009
On Mon, Nov 30, 2009 at 1:00 PM, Walter Bright <newshound1@digitalmars.com> wrote:
> Álvaro Castro-Castilla wrote:
>>
>> It does. Shouldn't this work also?
>>
>> struct foo {
>>    void opDispatch( string name, T... )( T values ) {    }   }
>>
>>                                                             void main( ) {
>>  foo f;
>>    f.bar( 3.14 );
>> }
>
> Declare as:
>
>    void opDispatch(string name, T...)(T values...)
>                                               ^^^

You didn't use to have to do that with variadic templates.  Is that also a new change in SVN?

Also, is there any chance you could paste the 1-line bug description
into your SVN commit messages?
For those of us who don't have the bug database memorized it would
make it much easier to find relevant commits.

(for instance I was scanning the commit log to see if there were any changes related to how variadic templates work, but all one sees is a list of commit messages like "bugzilla 3494".  Takes too long to figure such things out if you have to plug each number one-by-one into bugzilla.)

--bb
November 30, 2009
On Mon, 30 Nov 2009 19:07:38 +0100, Walter Bright <newshound1@digitalmars.com> wrote:

> Simen kjaeraas wrote:
>> This still does not compile:
>>  struct foo {
>>     void opDispatch( string name, T )( T value ) {
>>     }
>> }
>>  void main( ) {
>>     foo f;
>>     f.bar( 3.14 );
>> }
>>  test.d(10): Error: template instance opDispatch!("bar") does not match template
>> declaration opDispatch(string name,T)
>
> It works when I try it.

And here. So what are you complaining about? :p

Apparently, my build script was wonky, and didn't update correctly.

I'm already in love with this feature. We're gonna have a beautiful life together...

-- 
Simen
November 30, 2009
Bill Baxter wrote:
> On Mon, Nov 30, 2009 at 1:00 PM, Walter Bright
>>    void opDispatch(string name, T...)(T values...)
>>                                               ^^^
> 
> You didn't use to have to do that with variadic templates.  Is that
> also a new change in SVN?

I believe it was always like that.

> Also, is there any chance you could paste the 1-line bug description
> into your SVN commit messages?
> For those of us who don't have the bug database memorized it would
> make it much easier to find relevant commits.
> 
> (for instance I was scanning the commit log to see if there were any
> changes related to how variadic templates work, but all one sees is a
> list of commit messages like "bugzilla 3494".  Takes too long to
> figure such things out if you have to plug each number one-by-one into
> bugzilla.)

Probably :-)
November 30, 2009
Simen kjaeraas wrote:
> I'm already in love with this feature.

So am I. It seems to be incredibly powerful.

Looks to me you can do things like:

1. hook up to COM's IDispatch

2. create 'classes' at runtime

3. add methods to existing classes (monkey patching) that allow such extensions

4. provide an easy way for users to add plugins to an app

5. the already mentioned "swizzler" functions that are generated at runtime based on the name of the function
November 30, 2009
Walter Bright wrote:
> Bill Baxter wrote:
>> On Mon, Nov 30, 2009 at 1:00 PM, Walter Bright
>>>    void opDispatch(string name, T...)(T values...)
>>>                                               ^^^
>>
>> You didn't use to have to do that with variadic templates.  Is that
>> also a new change in SVN?
> 
> I believe it was always like that.
> 
What do you mean? Not the D I played with?

void test1(T...)(T ts) {
    writeln(ts); //works as expected
}
void test2(string s, T...)(T ts) {
    writeln(s);  // requires manual specifying of each type
    writeln(ts); // e.g. test2!("foo", int, int)(1,2)
}
void test3(string s, T...)(T ts...) {
    writeln(s);  // silently dies when called with
    writeln(ts); // test3!("foo")(1,2,3,4) in v2.034
}
November 30, 2009
On Mon, 30 Nov 2009 23:02:46 +0100, Walter Bright <newshound1@digitalmars.com> wrote:

> Simen kjaeraas wrote:
>> I'm already in love with this feature.
>
> So am I. It seems to be incredibly powerful.
>
> Looks to me you can do things like:
>
> 1. hook up to COM's IDispatch
>
> 2. create 'classes' at runtime
>
> 3. add methods to existing classes (monkey patching) that allow such extensions
>
> 4. provide an easy way for users to add plugins to an app
>
> 5. the already mentioned "swizzler" functions that are generated at runtime based on the name of the function

I know, and interfacing with scripting languages just got
even awesomer than it already was in D.

Oh, and another thing: Will we get property syntax for this?

I'd like to use this for shaders, allowing one to refer to
the shader's own variables directly from D, but currently I am
limited to function call syntax (unless I'm missing something?)

-- 
Simen
November 30, 2009
On Mon, 30 Nov 2009 23:13:23 +0100, Pelle Månsson <pelle.mansson@gmail.com> wrote:

> Walter Bright wrote:
>> Bill Baxter wrote:
>>> On Mon, Nov 30, 2009 at 1:00 PM, Walter Bright
>>>>    void opDispatch(string name, T...)(T values...)
>>>>                                               ^^^
>>>
>>> You didn't use to have to do that with variadic templates.  Is that
>>> also a new change in SVN?
>>  I believe it was always like that.
>>
> What do you mean? Not the D I played with?
>
> void test1(T...)(T ts) {
>      writeln(ts); //works as expected
> }
> void test2(string s, T...)(T ts) {
>      writeln(s);  // requires manual specifying of each type
>      writeln(ts); // e.g. test2!("foo", int, int)(1,2)
> }
> void test3(string s, T...)(T ts...) {
>      writeln(s);  // silently dies when called with
>      writeln(ts); // test3!("foo")(1,2,3,4) in v2.034
> }

It would seem Walter is right, but only for opDispatch. This compiles
fine. If you want compile errors, move the ellipsis around:


struct foo {
	void opDispatch( string name, T... )( T value... ) {
	}
	
	void bar( T... )( T args ) {
	}
}

void main( ) {
	foo f;
	f.bar( 3 );
	f.baz( 3.14 );
}

-- 
Simen
November 30, 2009
Simen kjaeraas wrote:
> On Mon, 30 Nov 2009 23:13:23 +0100, Pelle Månsson <pelle.mansson@gmail.com> wrote:
> 
>> Walter Bright wrote:
>>> Bill Baxter wrote:
>>>> On Mon, Nov 30, 2009 at 1:00 PM, Walter Bright
>>>>>    void opDispatch(string name, T...)(T values...)
>>>>>                                               ^^^
>>>>
>>>> You didn't use to have to do that with variadic templates.  Is that
>>>> also a new change in SVN?
>>>  I believe it was always like that.
>>>
>> What do you mean? Not the D I played with?
>>
>> void test1(T...)(T ts) {
>>      writeln(ts); //works as expected
>> }
>> void test2(string s, T...)(T ts) {
>>      writeln(s);  // requires manual specifying of each type
>>      writeln(ts); // e.g. test2!("foo", int, int)(1,2)
>> }
>> void test3(string s, T...)(T ts...) {
>>      writeln(s);  // silently dies when called with
>>      writeln(ts); // test3!("foo")(1,2,3,4) in v2.034
>> }
> 
> It would seem Walter is right, but only for opDispatch. This compiles
> fine. If you want compile errors, move the ellipsis around:
> 
> 
> struct foo {
>     void opDispatch( string name, T... )( T value... ) {
>     }
>         void bar( T... )( T args ) {
>     }
> }
> 
> void main( ) {
>     foo f;
>     f.bar( 3 );
>     f.baz( 3.14 );
> }
> 
So, why have this special case for opDispatch? Maybe I am missing something.
November 30, 2009
Simen kjaeraas wrote:
> Oh, and another thing: Will we get property syntax for this?
> 
> I'd like to use this for shaders, allowing one to refer to
> the shader's own variables directly from D, but currently I am
> limited to function call syntax (unless I'm missing something?)

You can do it, but be careful - you cannot add data members to a class by using templates. You'll have to fake them, by using enums, or a pointer to the actual data, etc.
November 30, 2009
Simen kjaeraas wrote:
> It would seem Walter is right, but only for opDispatch. This compiles
> fine. If you want compile errors, move the ellipsis around:

Hmm, looks like there is a problem, but it has nothing to do with opDispatch, as this:

    void bar(string s, T...)(T args)

doesn't work either.