A feture adjustment request and a syntax blasphemy
BCS
nobody at pathlink.com
Sun Oct 29 20:54:36 PST 2006
Closures and currying provide some of what I was looking for. However, if I
understand them correctly*, they don't do exactly what I want.
The closure approach would be fine if it didn't require some language magic or
annotations to get the local parameters off the stack. The system I used avoids
this by dynamically allocating off the heap for the context. (this is only better
than annotation because it doesn’t require language support)
Currying (again, if I understand correctly) will end up using some sort of runtime
generated function or a wrapper delegate that manipulates the stack (another form
of a closure) again this doesn’t quite have the effect I'm looking for. In this
case it is because of the extra call/return overhead.
Really what I want is to be able to form a delegate from any heap item and a
literal code block. particularly I want the context of such a thing to be the heap
item, not the enclosing scope.
<ptr_type>.delegate <type>(<type_list>){<code>}
FWIW, I got the program I posted working but had to use an anonymous class with
the function as a method. Not as clean a solution because of the overhead
involving objects, but it works.
{
auto c = new class{
T delegate() d;
T action()
{
return d();
}
}
return &a.action;
}
*I haven’t read the article DavidM cited yet (lack of time n'all)
== Quote from Jarrett Billingsley (kb3ctd2 at yahoo.com)'s article
> "BCS" <BCS at pathlink.com> wrote in message
> > So why no this?
> >
> > static int[] i = [1,2,3];
> > i.function void(int[] j){return;}();
> How about:
> static int[] i = [1,2,3];
> auto f = function void(int[] j){return;};
> i.f();
> ?
I was trying to get away without the temporary. If you will notice, you suggestion
is effectively the same as the example of something that works that I gave.
More information about the Digitalmars-d-learn
mailing list