digitalmars.D - A humble request.
- pragma (39/39) Aug 03 2004 Walter,
- Walter (14/52) Aug 03 2004 enough
- pragma (9/33) Aug 03 2004 Yes it can, and it probably should. :)
- Juanjo =?ISO-8859-15?Q?=C1lvarez?= (2/6) Aug 03 2004 For example this is very usefull on GUI programming.
- pragma (7/13) Aug 03 2004 Actually, I had that in mind when I wrote my original post. I'm pretty ...
Walter, I would like to submit an idea for two features that I feel are strong enough for version 2.0 at the very least. I would like to see added to D is an event or multicast delegate mechanism, similar to what C# has. I'd like to advocate expanding arrays of functions and delegates to allowing a call on the array to apply to all elements of the underlying array: delegate(char[] reason)[] onShutdown; onShutdown ~= &dllManager.unloadLibraries; onShutdown ~= &threadManager.stopThreads; onShutdown("The server is shutting down."); // calls everything in the array This could have some interesting implications on arrays of objects and opCall as well. My quest for this kind of functionality has lead me to write a template, for which i'd ideally like to do the following: template multicast(DT : RT delegate(T1)){ RT muticast(DT[] delegateArray,T1 one){ foreach(DT thisDelegate; delegateArray){ thisDelegate(one); } } } This leads me to my second request: is there any way that delegate and function parameter and return types may be treated in the same regard as first-class template parameters? Right now, it just isn't possible to specialize a template based on a generic delegate type. One can use a specific delegate type instead, but even then you still can't pick apart the delegate to get the return or parameter types. The following is the cannonical example of how dmd doesn't like this: // test.d template Foo(DT: RT delegate(T1,T2,T3)){ } test.d(2): identifier 'RT' is not defined // test2.d template Foo(RT delegate(T1,T2,T3)){ } test2.d(2): no identifier for template value parameter test2.d(2): Declaration expected, not ')' - Pragma
Aug 03 2004
"pragma" <EricAnderton at yahoo dot compragma_member pathlink.com> wrote in message news:ceodn0$1bhp$1 digitaldaemon.com...Walter, I would like to submit an idea for two features that I feel are strongenoughfor version 2.0 at the very least. I would like to see added to D is an event or multicast delegatemechanism,similar to what C# has. I'd like to advocate expanding arrays offunctions anddelegates to allowing a call on the array to apply to all elements of the underlying array: delegate(char[] reason)[] onShutdown; onShutdown ~= &dllManager.unloadLibraries; onShutdown ~= &threadManager.stopThreads; onShutdown("The server is shutting down."); // calls everything in thearrayThis could have some interesting implications on arrays of objects andopCall aswell.Can't foreach do this job?My quest for this kind of functionality has lead me to write a template,forwhich i'd ideally like to do the following: template multicast(DT : RT delegate(T1)){ RT muticast(DT[] delegateArray,T1 one){ foreach(DT thisDelegate; delegateArray){ thisDelegate(one); } } } This leads me to my second request: is there any way that delegate andfunctionparameter and return types may be treated in the same regard asfirst-classtemplate parameters? Right now, it just isn't possible to specialize a template based on agenericdelegate type. One can use a specific delegate type instead, but eventhen youstill can't pick apart the delegate to get the return or parameter types. The following is the cannonical example of how dmd doesn't like this: // test.d template Foo(DT: RT delegate(T1,T2,T3)){ } test.d(2): identifier 'RT' is not defined // test2.d template Foo(RT delegate(T1,T2,T3)){ } test2.d(2): no identifier for template value parameter test2.d(2): Declaration expected, not ')'Ok, I see.
Aug 03 2004
In article <ceojbj$1eaa$1 digitaldaemon.com>, Walter says..."pragma" <EricAnderton at yahoo dot compragma_member pathlink.com> wrote inYes it can, and it probably should. :) My desire here was to have a mechanism that would make an 'event' look and behave as a single delegate. This is both useful and dangerous, depending on how one looks at it. Personally, I feel that it would make for a more powerful and expressive grammar without extra syntactic clutter (i.e. extra keywords, simple loops or templates).delegate(char[] reason)[] onShutdown; onShutdown ~= &dllManager.unloadLibraries; onShutdown ~= &threadManager.stopThreads; onShutdown("The server is shutting down."); // calls everything in thearrayCan't foreach do this job?Thank you for reading my post Walter. :) - PragmaThe following is the cannonical example of how dmd doesn't like this: // test.d template Foo(DT: RT delegate(T1,T2,T3)){ } test.d(2): identifier 'RT' is not defined // test2.d template Foo(RT delegate(T1,T2,T3)){ } test2.d(2): no identifier for template value parameter test2.d(2): Declaration expected, not ')'Ok, I see.
Aug 03 2004
pragma wrote:My desire here was to have a mechanism that would make an 'event' look and behave as a single delegate. This is both useful and dangerous, depending on how one looks at it.For example this is very usefull on GUI programming.
Aug 03 2004
In article <ceoskl$1jaq$1 digitaldaemon.com>, Juanjo =?ISO-8859-15?Q?=C1lvarez?= says...pragma wrote:Actually, I had that in mind when I wrote my original post. I'm pretty sure GUI programming was the motivating factor behind the event keyword in C# as well. If we're lucky enough for D to get templates expanded to specialize on delegate types, then it'd be easy to write a good class to cover this. :) - PragmaMy desire here was to have a mechanism that would make an 'event' look and behave as a single delegate. This is both useful and dangerous, depending on how one looks at it.For example this is very usefull on GUI programming.
Aug 03 2004