D - D alpha 26
- Walter (4/4) Apr 10 2002 ftp://www.digitalmars.com/dmdalpha.zip
- Pavel Minayev (4/5) Apr 10 2002 OH YES!
- J. Daniel Smith (57/61) Apr 10 2002 Is the plan to leave the task of maintaining a collection of delegates t...
- Walter (7/74) Apr 10 2002 Yes. A delegate and a set are two distinct things, and I don't think the...
- Russ Lewis (8/14) Apr 10 2002 Doesn't seem too hard to declare an array of delegates and have a the ca...
- Walter (8/17) Apr 10 2002 to
- J. Daniel Smith (14/29) Apr 11 2002 Well, other than that for event handling you normally want a set, not an
- Walter (5/7) Apr 11 2002 Probably the easiest way is to use an associative array. Use the delegat...
- Russ Lewis (16/23) Apr 11 2002 That would work. Or you could have an associative array with the delega...
- Russ Lewis (16/16) Apr 11 2002 More thoughts about this...the concatenate operator might be useful for ...
- J. Daniel Smith (20/36) Apr 11 2002 My sample code for adding multiple delegates is pretty ugly:
- OddesE (9/13) Apr 10 2002 Thank you!
ftp://www.digitalmars.com/dmdalpha.zip This implements delegates, described in www.digitalmars.com/d/type.html It also works under Win98 now. -Walter
Apr 10 2002
"Walter" <walter digitalmars.com> wrote in message news:a90tao$154a$1 digitaldaemon.com...This implements delegates, described in www.digitalmars.com/d/type.htmlOH YES! Expect strong WinD soon...
Apr 10 2002
Is the plan to leave the task of maintaining a collection of delegates to the programmer? This is needed to easily implement event handling. But, assuming you can make a delegate typedef in D (can you?), the syntax Here's a simple D sample (the syntax may not be quite right) class DelegatesAndEvents { typedef void delegate(int) dg_t; // dg_t dg; // dg is a delegate to a function dg_t[] MyEvent; void Fire_MyEvent(int event_data) { for (int i=0; i<MyEvent.length; i++) { dg_t e = MyEvent[i]; e(event_data); } } } class OB { void member(int); } class OB2 { void func(int); } OB o = new OB(); OB2 o2 = new OB2(); DelegatesAndEvents dae; DelegatesAndEvents.dt_t[0] a_delegate; a_delegate[0] = &o.member; dae.MyEvent ~= a_delegate; a_delegate[0] = &o2.func; dae.MyEvent ~= a_delegate; dae.Fire_MyEvent(314); class DelegatesAndEvents { public delegate void dg_t(int); public event dg_t MyEvent; public void Fire_MyEvent(int event_data) { MyEvent(event_data); } }; class OB { void member(int); } class OB2 { void func(int); } OB o = new OB(); OB2 o2 = new OB2(); DelegatesAndEvents dae = new DelegatesAndEvents(); dae.MyEvent += new DelegatesAndEvents.MyEvent(o.member); dae.MyEvent += new DelegatesAndEvents.MyEvent(o2.func); dae.Fire_MyEvent(314); to build up a collection of delegates; as far as I can tell, that's slightly more cumbersome in D because of having to append arrays. However, there are two important semantic differences between the code snipets: "MyEvent" is better thought of as a set rather than an array, adding the same delegate twice will NOT cause that delegate to get invoked multiple times. The other difference is that in keeping with the "set" data structure, the invocation order is not defined. Dan "Walter" <walter digitalmars.com> wrote in message news:a90tao$154a$1 digitaldaemon.com...ftp://www.digitalmars.com/dmdalpha.zip This implements delegates, described in www.digitalmars.com/d/type.html It also works under Win98 now. -Walter
Apr 10 2002
"J. Daniel Smith" <j_daniel_smith HoTMaiL.com> wrote in message news:a91he8$1o7v$1 digitaldaemon.com...Is the plan to leave the task of maintaining a collection of delegates to the programmer?Yes. A delegate and a set are two distinct things, and I don't think theyThis is needed to easily implement event handling. But, assuming you can make a delegate typedef in D (can you?), the syntax Here's a simple D sample (the syntax may not be quite right) class DelegatesAndEvents { typedef void delegate(int) dg_t; // dg_t dg; // dg is adelegateto a function dg_t[] MyEvent; void Fire_MyEvent(int event_data) { for (int i=0; i<MyEvent.length; i++) { dg_t e = MyEvent[i]; e(event_data); } } } class OB { void member(int); } class OB2 { void func(int); } OB o = new OB(); OB2 o2 = new OB2(); DelegatesAndEvents dae; DelegatesAndEvents.dt_t[0] a_delegate; a_delegate[0] = &o.member; dae.MyEvent ~= a_delegate; a_delegate[0] = &o2.func; dae.MyEvent ~= a_delegate; dae.Fire_MyEvent(314); class DelegatesAndEvents { public delegate void dg_t(int); public event dg_t MyEvent; public void Fire_MyEvent(int event_data) { MyEvent(event_data); } }; class OB { void member(int); } class OB2 { void func(int); } OB o = new OB(); OB2 o2 = new OB2(); DelegatesAndEvents dae = new DelegatesAndEvents(); dae.MyEvent += new DelegatesAndEvents.MyEvent(o.member); dae.MyEvent += new DelegatesAndEvents.MyEvent(o2.func); dae.Fire_MyEvent(314); to build up a collection of delegates; as far as I can tell, that'sslightlymore cumbersome in D because of having to append arrays. However, there are two important semantic differences between the code snipets: "MyEvent" is better thought of as a set rather than an array, adding the same delegate twice will NOT cause that delegate to get invoked multiple times. The other difference is that in keeping with the "set"datastructure, the invocation order is not defined. Dan "Walter" <walter digitalmars.com> wrote in message news:a90tao$154a$1 digitaldaemon.com...ftp://www.digitalmars.com/dmdalpha.zip This implements delegates, described in www.digitalmars.com/d/type.html It also works under Win98 now. -Walter
Apr 10 2002
Walter wrote:"J. Daniel Smith" <j_daniel_smith HoTMaiL.com> wrote in message news:a91he8$1o7v$1 digitaldaemon.com...Doesn't seem too hard to declare an array of delegates and have a the caller iterate through it when an event happens... -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]Is the plan to leave the task of maintaining a collection of delegates to the programmer?Yes. A delegate and a set are two distinct things, and I don't think they
Apr 10 2002
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:3CB4CA05.915224EF deming-os.org...Walter wrote:to"J. Daniel Smith" <j_daniel_smith HoTMaiL.com> wrote in message news:a91he8$1o7v$1 digitaldaemon.com...Is the plan to leave the task of maintaining a collection of delegatestheythe programmer?Yes. A delegate and a set are two distinct things, and I don't thinkcallerDoesn't seem too hard to declare an array of delegates and have a theiterate through it when an event happens...I agree, and with such code you can see and understand what's happening. which is why I find it confusing.
Apr 10 2002
Well, other than that for event handling you normally want a set, not an array. This makes it easy for multiple places in the code to add the same event handler without the worry of it getting called multiple times. I guess leaving it up to the programmer makes it easier to handle situations where you really want the delelgates invoked in the same (or reverse) order as they were added. Is there an easy way to do set manipulation in D, or is that the responsibility of some library class? Dan "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:3CB4CA05.915224EF deming-os.org...Walter wrote:to"J. Daniel Smith" <j_daniel_smith HoTMaiL.com> wrote in message news:a91he8$1o7v$1 digitaldaemon.com...Is the plan to leave the task of maintaining a collection of delegatestheythe programmer?Yes. A delegate and a set are two distinct things, and I don't thinkcallerDoesn't seem too hard to declare an array of delegates and have a theiterate through it when an event happens... -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Apr 11 2002
"J. Daniel Smith" <j_daniel_smith HoTMaiL.com> wrote in message news:a940r6$1d86$1 digitaldaemon.com...Is there an easy way to do set manipulation in D, or is that the responsibility of some library class?Probably the easiest way is to use an associative array. Use the delegate as both the key and the value. That way each unique delegate will only appear once in the associative array.
Apr 11 2002
Walter wrote:"J. Daniel Smith" <j_daniel_smith HoTMaiL.com> wrote in message news:a940r6$1d86$1 digitaldaemon.com...That would work. Or you could have an associative array with the delegate as the key and some kind of info about it in the data... Of course, maybe you don't need any data, so you just include a bool or int value that is never accessed... Oh, wait, now we're talking about a set, implemented by the compiler, but with the wasted space of all those junk variables... Maybe it would make sense to leverage existing associative array code and give us a set fundamental type? :) It can have size, length, rehash, and keys properties, all like an associative array. It just wouldn't have a values property... -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]Is there an easy way to do set manipulation in D, or is that the responsibility of some library class?Probably the easiest way is to use an associative array. Use the delegate as both the key and the value. That way each unique delegate will only appear once in the associative array.
Apr 11 2002
More thoughts about this...the concatenate operator might be useful for combining associative arrays/sets; the problem is, what do you do if there are any conflicting keys? It might suggest a full set of operators for associative arrays/sets: union junction exclusion (dunno the official name...the backslash operator) Of course, now we're heading toward a much more complex implementation for sets, one that might be in a class. But it seems like a simple and logical extension; associative arrays lead to sets, and sets lead to built-in set operators. My 2 cents, anyhow. -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Apr 11 2002
My sample code for adding multiple delegates is pretty ugly: dg_t[] MyEvent; // ... DelegatesAndEvents.dt_t[0] a_delegate; a_delegate[0] = &o.member; dae.MyEvent ~= a_delegate; a_delegate[0] = &o2.func; dae.MyEvent ~= a_delegate; something like dg_t[] MyEvent; // ... dae.MyEvent += &o.member; dae.MyEvent += &o2.func; would cleaner. Dan "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:3CB5CB05.8347198C deming-os.org...More thoughts about this...the concatenate operator might be useful forcombiningassociative arrays/sets; the problem is, what do you do if there are any conflicting keys? It might suggest a full set of operators for associative arrays/sets: union junction exclusion (dunno the official name...the backslash operator) Of course, now we're heading toward a much more complex implementation forsets,one that might be in a class. But it seems like a simple and logicalextension;associative arrays lead to sets, and sets lead to built-in set operators. My 2 cents, anyhow. -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Apr 11 2002
"Walter" <walter digitalmars.com> wrote in message news:a90tao$154a$1 digitaldaemon.com...ftp://www.digitalmars.com/dmdalpha.zip This implements delegates, described in www.digitalmars.com/d/type.html It also works under Win98 now. -WalterThank you! -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
Apr 10 2002