bearophile wrote:
Jesse Phillips:
I seem to recall the distinction was going to be going away or minimized. Is this 
already done? Will it be going into D2?<

D2 docs say:
http://www.digitalmars.com/d/2.0/function.html
Future directions: Function pointers and delegates may merge into a common syntax 
and be interchangeable with each other.<

I think the situation isn't changed. It's one of the *many* details that look 
forgotten. There's usually time to fix them later once the big things are in 
place.

Bye,
bearophile

Perhaps "functions" should be eliminated except for being accessed via a delegate's .funcptr property (which could also be used for c compatibility). In addition,

int foo(int a) {};

would be the same as:

const int delegate(int) foo = delegate int(int a) {};

I don't have D2 installed, but the above fails to compile in d1 (non-constant expression __dgliteral1). I've also always found the above syntax confusing, on the left we have "int delegate" and on the right, "delegate int". Perhaps it should always be "int delegate", and whether a function body is present determines whether the expression is a type or an anonymous function. "int delegate" is also similar to how other functions are defined, since "delegate" simply replaces the function name, and it's similar to other languages, such as ECMA script v4 (ActionScript 3)

Perhaps also, functions should have available an arguments property that would be a struct of the functions arguments, of type ParamTypeTuple!(func), e.g.

void foo(int a)
{       bar(foo.arguments);
}
void bar(int a)
{       writefln(bar.arguments.a); // writes 3
        writefln(a); // writes 3
}
foo(3);

To me, this is much more straightforward than using std.stdarg when varargs come into play. Perhaps foo.closure could reference any variables captured in a closure.

Finally, in D2, was a way ever figured out to differentiate between delegates and closures, so that delegates can be used w/o heap allocation?

Hopefully I didn't come across as dictating policy. These are just my ideas for simplifying functions/delegates in D2 or beyond.

Reply via email to