Moritz Warning wrote:
On Tue, 30 Jun 2009 11:38:21 -0400, Jesse Phillips wrote:

So looking at a post on StackOverflow about D gatchas:
http://stackoverflow.com/questions/743319/why-isnt-the-d-language-
picking-up/1059780#1059780
"functions that form closures or are attached to objects (ie. methods)
are not the same as regular functions, instead they are called
delegates, and you must be aware of the differences."

I seem to recall the distinction was going to be going away or
minimized. Is this already done? Will it be going into D2?

fwiw, that's what I use to convert a function to a delegate (not my invention):

R delegate(T) toDg(R, T...)(R function(T) fp)
{
        struct dg
        {
                R opCall(T t)
                {
                        return (cast(R function(T)) this) (t);
                }
        }
        
        R delegate(T) t;
        t.ptr = fp;
        t.funcptr = &dg.opCall;
        return t;
}

Note that this won't work for ref arguments.

I use this too, but my point was that it'd be nice if hacks like this weren't required, e.g. by doing away with functions except for C compatibility and making everything a delegate internally.

Reply via email to