digitalmars.D - Q: how to do AA of delegates keyed by int?
- Brian Chapman (16/16) Feb 01 2005 Help? I'm having trouble figuring out how to get a delegate out of an AA...
- Carlos Santander (4/20) Feb 01 2005 ----------------
- Stewart Gordon (11/32) Feb 01 2005 Have you tried the 'normal' method?
- pragma (10/19) Feb 01 2005 Actually, its not a bug. The 'in' operator is a 'boolean' operation ("d...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (6/18) Feb 01 2005 The return type of "in" was changed in DMD 0.107, from bit to pointer.
- pragma (5/13) Feb 01 2005 Well, crap. Sorry if I mislead anyone. :(
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (5/9) Feb 01 2005 On the contrary, your "no side-effects" code still works -
- Regan Heath (18/29) Feb 01 2005 Didn't this change? i.e.
- Brian Chapman (13/21) Feb 01 2005 Thanks Everyone!
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (7/14) Feb 02 2005 I'm using GDC-0.10 with GCC-3.3.5, but on the latest Mac OS X 10.3.7...
- Brian Chapman (13/33) Feb 03 2005 Well, you wont believe this but I went back to nail down the problem so
- Walter (3/4) Feb 01 2005 I think you might be using an older DMD version. Try upgrading to 0.111.
Help? I'm having trouble figuring out how to get a delegate out of an AA. void delegate() hash [int]; int key = 5; hash[key] = delegate void() {printf ("whee!\n");}; Now how do I go about getting that value out? void delegate() fn = (key in hash); doesn't work and neither does: void delegate()* fn = (key in hash); which according to the docs I would think is how it is supposed to work seeing how it's supposed to return a pointer to the value type. But the compiler says: "cannot implicitly convert expression key in hash of type int to void delegate()*" I give up. What am I doing wrong? Thanks in advance for putting up with my lameness. ;-)
Feb 01 2005
In article <ctns13$8fu$1 digitaldaemon.com>, Brian Chapman says...Help? I'm having trouble figuring out how to get a delegate out of an AA. void delegate() hash [int]; int key = 5; hash[key] = delegate void() {printf ("whee!\n");}; Now how do I go about getting that value out? void delegate() fn = (key in hash); doesn't work and neither does: void delegate()* fn = (key in hash);This one works for me (dmd 0.111, winxp)which according to the docs I would think is how it is supposed to work seeing how it's supposed to return a pointer to the value type. But the compiler says: "cannot implicitly convert expression key in hash of type int to void delegate()*" I give up. What am I doing wrong? Thanks in advance for putting up with my lameness. ;-)---------------- Carlos Santander
Feb 01 2005
Brian Chapman wrote:Help? I'm having trouble figuring out how to get a delegate out of an AA. void delegate() hash [int]; int key = 5; hash[key] = delegate void() {printf ("whee!\n");}; Now how do I go about getting that value out?Have you tried the 'normal' method? void delegate() fn = hash[key];void delegate() fn = (key in hash); doesn't workCorrect, as the InExpression should be of type pointer to delegate.and neither does: void delegate()* fn = (key in hash); which according to the docs I would think is how it is supposed to work seeing how it's supposed to return a pointer to the value type. But the compiler says: "cannot implicitly convert expression key in hash of type int to void a delegate()*"<snip> This should work. It looks as if the in operator has a bug or two with determining its return type. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Feb 01 2005
In article <cto6bg$kkb$1 digitaldaemon.com>, Stewart Gordon says...Actually, its not a bug. The 'in' operator is a 'boolean' operation ("does this key exist in the map?"), so it returns 'int' (true/false actually). Also, Stewart's suggestion of "hash[key]" is the correct approach, however it does have the side-effect of generating an empty value for 'key' (the AA grows as a result) if the key doesn't already exist in the map. The result is 'fn' gets assigned null, but future checks to "key in hash" will return true, not false. The side-effect free code is like this:"cannot implicitly convert expression key in hash of type int to void a delegate()*"<snip> This should work. It looks as if the in operator has a bug or two with determining its return type.void delegate fn; if(key in hash){ fn = hash[key]; }- EricAnderton at yahoo
Feb 01 2005
pragma wrote:Actually, its not a bug. The 'in' operator is a 'boolean' operation ("does this key exist in the map?"), so it returns 'int' (true/false actually).The return type of "in" was changed in DMD 0.107, from bit to pointer. http://www.digitalmars.com/d/changelog.html#new0107InExpressions now, instead of returning a bit, return a pointer to the associative array element if the key is present, null if it is not. This obviates the need for many double lookups.http://www.digitalmars.com/d/arrays.html#associativeThe InExpression yields a pointer to the value if the key is in the associative array, or null if not: int* p; p = ("hello" in b); if (p != null) ...Not that D cares about the difference between false and null anyway. --anders
Feb 01 2005
In article <cto98f$njs$1 digitaldaemon.com>, =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= says...pragma wrote:Well, crap. Sorry if I mislead anyone. :( I'll read the changelog a little more closely for now on! - EricAnderton at yahooActually, its not a bug. The 'in' operator is a 'boolean' operation ("does this key exist in the map?"), so it returns 'int' (true/false actually).The return type of "in" was changed in DMD 0.107, from bit to pointer. http://www.digitalmars.com/d/changelog.html#new0107InExpressions now, instead of returning a bit, return a pointer to the associative array element if the key is present, null if it is not. This obviates the need for many double lookups.
Feb 01 2005
pragma wrote:The return type of "in" was changed in DMD 0.107, from bit to pointer.Well, crap. Sorry if I mislead anyone. :( I'll read the changelog a little more closely for now on!On the contrary, your "no side-effects" code still works - and seems to be the only one not affected by new "in" bugs ? "if (key in hash)" still works, just as "if (object)" does. --anders
Feb 01 2005
On Tue, 1 Feb 2005 15:56:43 +0000 (UTC), pragma <pragma_member pathlink.com> wrote:In article <cto6bg$kkb$1 digitaldaemon.com>, Stewart Gordon says...Didn't this change? i.e. "What's New for D 0.107 Nov 29, 2004 ... InExpressions now, instead of returning a bit, return a pointer to the associative array element if the key is present, null if it is not. This obviates the need for many double lookups." http://www.digitalmars.com/d/arrays.html#associative "The InExpression yields a pointer to the value if the key is in the associative array, or null if not: int* p; p = ("hello" in b); if (p != null) ..." <snip> ReganActually, its not a bug. The 'in' operator is a 'boolean' operation ("does this key exist in the map?"), so it returns 'int' (true/false actually)."cannot implicitly convert expression key in hash of type int to void a delegate()*"<snip> This should work. It looks as if the in operator has a bug or two with determining its return type.
Feb 01 2005
On 2005-02-01 09:56:43 -0600, pragma <pragma_member pathlink.com> said:The side-effect free code is like this:Thanks Everyone! Walter's suspicion was correct. I was indeed using an older version (but yet reading the latest docs). I'm still using GDC-0.08/GCC-3.3.4 (on Mac OS X 10.2.8) because I couldn't get GDC-0.10 to work with GCC-3.3.4 which means I'm probably going to have to download the latest GCC. However, I live on a puny modem (56k that only connects at 28.8) and so I procrastinate downloading big files a lot, GCC being one of them. But yeah I should get it done nonetheless. Anyway, I was able to get it to work with Eric's side-effect free code. So thank you for that! I guess a little double-lookup won't hurt me till I pull in the new GCC/GDC. Thanks again guys. You big! Me small. ;-)void delegate fn; if(key in hash){ fn = hash[key]; }- EricAnderton at yahoo
Feb 01 2005
Brian Chapman wrote:Walter's suspicion was correct. I was indeed using an older version (but yet reading the latest docs). I'm still using GDC-0.08/GCC-3.3.4 (on Mac OS X 10.2.8) because I couldn't get GDC-0.10 to work with GCC-3.3.4 which means I'm probably going to have to download the latest GCC.I'm using GDC-0.10 with GCC-3.3.5, but on the latest Mac OS X 10.3.7... Did you post the compiler errors you get on the digitalmars.D.gnu group?However, I live on a puny modem (56k that only connects at 28.8) and so I procrastinate downloading big files a lot, GCC being one of them. But yeah I should get it done nonetheless.Can't you just order a CD ? Lots of places sell distfiles like gcc. Still have to get Mango 1.1 to compile with this compiler/platform, though. And of course, there's also the goodies from DMD 0.111/0.112 --anders
Feb 02 2005
On 2005-02-02 04:09:14 -0600, =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> said:Brian Chapman wrote:Well, you wont believe this but I went back to nail down the problem so I could tell you what it was and found out it was something really simple, all be it, very odd. Somehow a -Werror flag had creeped into my DFLAGS makefile variable. It was causing GDC to output a sparse object file and leaving a nice .s file in the working directory for each .d file compiled. Took that W flag out and it works fine. Put it back in and weirdness. You know, those GCC guys are never gonna take us seriously with that kind of goofiness going on. ;-)Walter's suspicion was correct. I was indeed using an older version (but yet reading the latest docs). I'm still using GDC-0.08/GCC-3.3.4 (on Mac OS X 10.2.8) because I couldn't get GDC-0.10 to work with GCC-3.3.4 which means I'm probably going to have to download the latest GCC.I'm using GDC-0.10 with GCC-3.3.5, but on the latest Mac OS X 10.3.7... Did you post the compiler errors you get on the digitalmars.D.gnu group?Yeah I used to do that. Place called Cheap Bytes. I don't know if they are still around. It's not so bad if I remember to stick wget on it before I go to bed. ;-)However, I live on a puny modem (56k that only connects at 28.8) and so I procrastinate downloading big files a lot, GCC being one of them. But yeah I should get it done nonetheless.Can't you just order a CD ? Lots of places sell distfiles like gcc.Still have to get Mango 1.1 to compile with this compiler/platform, though. And of course, there's also the goodies from DMD 0.111/0.112 --anders
Feb 03 2005
"Brian Chapman" <nospam-for-brian see-post-for-address.net> wrote in message news:ctns13$8fu$1 digitaldaemon.com...I give up. What am I doing wrong?I think you might be using an older DMD version. Try upgrading to 0.111.
Feb 01 2005