May 23, 2011
On 5/22/11, Timon Gehr <timon.gehr@gmx.ch> wrote:
> The problem is, that currently there is no other
> I do not get why anybody would want to remove the possibility to refer to
> function
> signatures.

What's wrong with using this:

alias void function(int, int) funcAlias;
May 23, 2011
On 5/23/11 8:41 AM, Andrej Mitrovic wrote:
> On 5/22/11, Timon Gehr<timon.gehr@gmx.ch>  wrote:
>> The problem is, that currently there is no other
>> I do not get why anybody would want to remove the possibility to refer to
>> function
>> signatures.
>
> What's wrong with using this:
>
> alias void function(int, int) funcAlias;

It's a function pointer type, not a function type.

David
May 23, 2011
Ah ok.

Hey if it's used for something useful I won't steal it from you. ;)
May 23, 2011
On Sun, 22 May 2011 11:20:15 -0400, Timon Gehr <timon.gehr@gmx.ch> wrote:

> Andrej Mitrovic wrote:
>> Should I file a bug report to kill this syntax?
>
> No. It is perfectly valid, see grammar:
> http://www.digitalmars.com/d/2.0/declaration.html
>
> What is strange about this syntax in particular?
>
> int i; //declares i of type "int"
> alias int i; //defines i as type "int"
>
> int func(int); //declares func of type "function that takes int and returns int"
> alias int func(int); //defines func as type "function that takes int and returns int"
>
> It is perfectly consistent with other uses of alias.

It is not perfectly consistent.  The function type syntax is useless, because you can only use it if you use the pointer modifier with it.  If you want to declare a function pointer, there are other (better) ways.

Yes, removing it would be a "special case" for the compiler, but it's syntax and usages are so bizzare, nobody would miss it.  it's akin to making:

if(x);

invalid.  Yes, it's valid syntax, but it's almost certainly not what the user wanted.  It's special cased for failure, to aid the developer in writing less buggy programs.  This would be a similar change, and I actually thought it was already in the compiler.

I'll throw it back at you, do you see a good use case for it?  And no, porting C code isn't a good use case.

-Steve
May 23, 2011
Steven Schveighoffer wrote:
> It is not perfectly consistent.  The function type syntax is useless, because you can only use it if you use the pointer modifier with it.  If you want to declare a function pointer, there are other (better) ways.

Yes, other ways of declaring a function pointer are better. But there is no other way than alias for referring to a function type... It is not useless, see below.

>
> Yes, removing it would be a "special case" for the compiler, but it's syntax and usages are so bizzare, nobody would miss it.

I would. For the usages part, not the syntax part.

> it's akin to
> making:
>
> if(x);
>
> invalid. Yes, it's valid syntax, but it's almost certainly not what the user wanted.  It's special cased for failure, to aid the developer in writing less buggy programs.  This would be a similar change, and I actually thought it was already in the compiler.

It is in the compiler. It is actually not valid syntax anymore (disallowed by grammar and caught by the parser). And it is not similar to removing function type alias. You can write if(x){} as a replacement if you need it.

There is currently no alternative for the alias.

>
> I'll throw it back at you, do you see a good use case for it?  And no, porting C code isn't a good use case.
>
> -Steve

There are no alias in C code.

I actually gave one:
Timon Gehr wrote:
> alias int func();
>
> int main(){
>     static assert(is(typeof(main)==func);
>     return 0;
> }

You can use something similar to this to constrain templates. I do not say this syntax is good. But at the moment we have nothing better than that. How DMD handles function types is closer to how C does it than me or you would like, see my other post.

BTW:

writeln(typeid(int function(int))); //int()*

wtf?


Timon
May 23, 2011
On 5/23/11, Timon Gehr <timon.gehr@gmx.ch> wrote:
> BTW:
>
> writeln(typeid(int function(int))); //int()*
>
> wtf?

Yeah, typeid generally seems to be bad for these things. typeof.stringof to the rescue:

writeln((int function(int)).stringof);  // int function(int)
May 23, 2011
Well if there's no better way to do it and it's useful, we should do a feature request for a better syntax, no?
May 23, 2011
On Mon, 23 May 2011 09:32:47 -0400, Timon Gehr <timon.gehr@gmx.ch> wrote:

> Steven Schveighoffer wrote:
>> it's akin to
>> making:
>>
>> if(x);
>>
>> invalid. Yes, it's valid syntax, but it's almost certainly not what the
>> user wanted.  It's special cased for failure, to aid the developer in
>> writing less buggy programs.  This would be a similar change, and I
>> actually thought it was already in the compiler.
>
> It is in the compiler. It is actually not valid syntax anymore (disallowed by
> grammar and caught by the parser).

When I said I thought it was already in the compiler, I meant the bizarro function type declaration, not the empty if statement.

> And it is not similar to removing function type
> alias. You can write if(x){} as a replacement if you need it.
>
> There is currently no alternative for the alias.

But why do you need a function type vs. a function pointer type?  Especially since the function pointer type is easily built from the function type, and you can't actually use the function type until you turn it into a function pointer.

>
>>
>> I'll throw it back at you, do you see a good use case for it?  And no,
>> porting C code isn't a good use case.
>
> There are no alias in C code.
>
> I actually gave one:
> Timon Gehr wrote:
>> alias int func();
>>
>> int main(){
>>     static assert(is(typeof(main)==func);
>>     return 0;
>> }

static assert(is(typeof(&main) == int function());

More straightforward and descriptive.

> BTW:
>
> writeln(typeid(int function(int))); //int()*
>
> wtf?

That needs to be fixed, the runtime's TypeInfo.toString methods are not always accurate (I think this warrants a bugzilla report).

-Steve
May 23, 2011
On Mon, 23 May 2011 09:59:01 -0400, Steven Schveighoffer <schveiguy@yahoo.com> wrote:

> On Mon, 23 May 2011 09:32:47 -0400, Timon Gehr <timon.gehr@gmx.ch> wrote:
>
>> Steven Schveighoffer wrote:
>>> it's akin to
>>> making:
>>>
>>> if(x);
>>>
>>> invalid. Yes, it's valid syntax, but it's almost certainly not what the
>>> user wanted.  It's special cased for failure, to aid the developer in
>>> writing less buggy programs.  This would be a similar change, and I
>>> actually thought it was already in the compiler.
>>
>> It is in the compiler. It is actually not valid syntax anymore (disallowed by
>> grammar and caught by the parser).
>
> When I said I thought it was already in the compiler, I meant the bizarro function type declaration, not the empty if statement.

I should clarify once again :)

I meant the *change to remove* the bizarro function type declaration.  I thought that was already decided and in the compiler (Don had a whole thread on this).

-Steve
May 23, 2011
Since &main can't be a template value argument, maybe he meant this use case:

alias int func();

void foo(alias T)()
{
    static assert(is(typeof(T) == func));
}

int main()
{
    foo!main;
    return 0;
}