digitalmars.D - Using <> for opCmp
- Lionello Lunesu (12/12) Nov 24 2006 The operator < > <= >= all use opCmp, but if you want to differentiate
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (6/12) Nov 24 2006 I would prefer using <=> for this, as that is what Perl already does...
- Lionello Lunesu (4/20) Nov 24 2006 The thing is, <> already exists! It's doing too much at the moment: it
- Stewart Gordon (13/15) Nov 26 2006 Exactly. And that's indeed what I'd expect it to do. Why do you feel
- Lionello Lunesu (25/31) Nov 27 2006 The original opCmp return value is lost, so currently <> is exactly the ...
- Don Clugston (11/22) Nov 27 2006 Not quite.
- Lionello Lunesu (7/29) Nov 27 2006 Right, for reals there's no simple "int opCmp", since there are more
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (6/13) Nov 27 2006 Or maybe you are wrong about it, and <> is in fact a boolean operator ?
- Bruno Medeiros (5/21) Nov 25 2006 Sure is kinda funny when we start using emoticons for operators... ^^
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (4/8) Nov 25 2006 Must be getting old (or not around the globe enough), hadn't seen those.
- Bruno Medeiros (7/19) Nov 28 2006 I don't understand the logic sequence between those two sentences: you
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (5/8) Nov 28 2006 Nah, I meant "if someone else needs to look it up, here's a link".
- Benji Smith (6/9) Nov 27 2006 I can't wait to see what kind of functionality can be provided using the...
-
Kyle Furlong
(2/15)
Nov 27 2006
Oooo, make it a D easter egg?!
- Stewart Gordon (12/13) Nov 28 2006 What's the point of hiding Easter eggs if we've already found them?
- Kyle Furlong (2/10) Nov 28 2006 We (early adopters) hide easter eggs for the new converts of 1.0 and bey...
The operator < > <= >= all use opCmp, but if you want to differentiate between the three cases (< == >) you either have to call opCmp yourself or use multiple comparisons. I'd like to suggest using the operator <> for an implicit call to opCmp, returning the actual comparison value (<0, 0, >0). * <> is already valid and used (albeit for floats only ATM) * if(x<>y) will work as supposed to without additional changes (in fact, it already does**) * no explicit reference to the hidden function "opCmp" L. **It seems that <> already works, but it returns a boolean true/false, instead of an integer, so it currently is the same as !=.
Nov 24 2006
Lionello Lunesu wrote:The operator < > <= >= all use opCmp, but if you want to differentiate between the three cases (< == >) you either have to call opCmp yourself or use multiple comparisons. I'd like to suggest using the operator <> for an implicit call to opCmp, returning the actual comparison value (<0, 0, >0).I would prefer using <=> for this, as that is what Perl already does... It is commonly used when writing sort functions, and called "starship". Think it was suggested before, but the language wasn't taking in any more operators at the time ? (The other one was ^^ for logical Xor.) --anders
Nov 24 2006
Anders F Björklund wrote:Lionello Lunesu wrote:The thing is, <> already exists! It's doing too much at the moment: it converts the int return value from opCmp to a boolean. L.The operator < > <= >= all use opCmp, but if you want to differentiate between the three cases (< == >) you either have to call opCmp yourself or use multiple comparisons. I'd like to suggest using the operator <> for an implicit call to opCmp, returning the actual comparison value (<0, 0, >0).I would prefer using <=> for this, as that is what Perl already does... It is commonly used when writing sort functions, and called "starship". Think it was suggested before, but the language wasn't taking in any more operators at the time ? (The other one was ^^ for logical Xor.) --anders
Nov 24 2006
Lionello Lunesu wrote: <snip>The thing is, <> already exists! It's doing too much at the moment: it converts the int return value from opCmp to a boolean.Exactly. And that's indeed what I'd expect it to do. Why do you feel that it's "too much"? Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Nov 26 2006
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:ekcecj$iig$1 digitaldaemon.com...Lionello Lunesu wrote: <snip>The original opCmp return value is lost, so currently <> is exactly the same as != (except using opCmp instead of opEquals, I'd hope). Converting the integer return value to a boolean is an extra operation, with added instructions. If this 'conversion to bool' was to be dropped, if (a<>b) would still behave the same way, with less instructions, and the added benifit of access to opCmp's value. At the moment, if you want to distinguish between the three cases, a<b, a==b, a>b, you will have to do two comparisons (resulting in either one call to opCmp and one to opEquals, or two calls to opCmp). To prevent these extra comparisons, you have to call opCmp explicitely, but then you'll have to know the type of the variables (for built-ins you need different code than for classes), not mentioning the fact that you reference the function opCmp (which I think should be hidden as much as possible). Now, if <> were to return the opCmp return value as an integer, you can do int cmp = a<>b; and have the three cases (<, ==, >) right there, without having to call opCmp, or worrying about the types. And it'll be faster code, too. I'm really rather surprised by the resistance. I'm not suggesting a new operator, merely changing an existing one slightly, improving its performance, whilst keeping it backward compatible. It should be a dead giveaway. Not getting people convinced shows how bad I am at making my point :S L.The thing is, <> already exists! It's doing too much at the moment: it converts the int return value from opCmp to a boolean.Exactly. And that's indeed what I'd expect it to do. Why do you feel that it's "too much"?
Nov 27 2006
Lionello Lunesu wrote:"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:ekcecj$iig$1 digitaldaemon.com...Not quite. x != y is not the same as x <> y if x and y are reals (eg, x=2, y = real.nan: x!=y is TRUE, but x <> y is FALSE). I would expect that in the future there'd be an opUnorderedCmp(), which the NCEG operators would use (As well as floating point, the NCEG operators could be used for tribools and SQL comparisions with NULL, for example).Lionello Lunesu wrote: <snip>The original opCmp return value is lost, so currently <> is exactly the same as != (except using opCmp instead of opEquals, I'd hope).The thing is, <> already exists! It's doing too much at the moment: it converts the int return value from opCmp to a boolean.Exactly. And that's indeed what I'd expect it to do. Why do you feel that it's "too much"?
Nov 27 2006
"Don Clugston" <dac nospam.com.au> wrote in message news:eke9uq$2et5$1 digitaldaemon.com...Lionello Lunesu wrote:Right, for reals there's no simple "int opCmp", since there are more relations than the usual three, but even for reals <> could be made to return an int, where a value of 0 would not only mean a==b, but also 'either a or b is NaN' (correct?) L."Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:ekcecj$iig$1 digitaldaemon.com...Not quite. x != y is not the same as x <> y if x and y are reals (eg, x=2, y = real.nan: x!=y is TRUE, but x <> y is FALSE). I would expect that in the future there'd be an opUnorderedCmp(), which the NCEG operators would use (As well as floating point, the NCEG operators could be used for tribools and SQL comparisions with NULL, for example).Lionello Lunesu wrote: <snip>The original opCmp return value is lost, so currently <> is exactly the same as != (except using opCmp instead of opEquals, I'd hope).The thing is, <> already exists! It's doing too much at the moment: it converts the int return value from opCmp to a boolean.Exactly. And that's indeed what I'd expect it to do. Why do you feel that it's "too much"?
Nov 27 2006
Lionello Lunesu wrote:The original opCmp return value is lost, so currently <> is exactly the same as != (except using opCmp instead of opEquals, I'd hope).But it seems to be using opEquals... At least it does when using GDC.I'm really rather surprised by the resistance. I'm not suggesting a new operator, merely changing an existing one slightly, improving its performance, whilst keeping it backward compatible. It should be a dead giveaway. Not getting people convinced shows how bad I am at making my point :SOr maybe you are wrong about it, and <> is in fact a boolean operator ? (i.e. as far as I know, != and <> are the same for non-floating types) I think opCmp should be give a new operator, but not holding my breath. --anders
Nov 27 2006
Anders F Björklund wrote:Lionello Lunesu wrote:Sure is kinda funny when we start using emoticons for operators... ^^ -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DThe operator < > <= >= all use opCmp, but if you want to differentiate between the three cases (< == >) you either have to call opCmp yourself or use multiple comparisons. I'd like to suggest using the operator <> for an implicit call to opCmp, returning the actual comparison value (<0, 0, >0).I would prefer using <=> for this, as that is what Perl already does... It is commonly used when writing sort functions, and called "starship". Think it was suggested before, but the language wasn't taking in any more operators at the time ? (The other one was ^^ for logical Xor.) --anders
Nov 25 2006
Bruno Medeiros wrote:Must be getting old (or not around the globe enough), hadn't seen those. (You too ? Look at http://en.wikipedia.org/wiki/Verticon for the {^_^} ) --andersThink it was suggested before, but the language wasn't taking in any more operators at the time ? (The other one was ^^ for logical Xor.)Sure is kinda funny when we start using emoticons for operators... ^^
Nov 25 2006
Anders F Björklund wrote:Bruno Medeiros wrote:I don't understand the logic sequence between those two sentences: you say you don't know that emoticon, but then you should you do, and ask if I don't know the emoticon? ... Huh? Of course I know. Confusion ensues :P ) -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DMust be getting old (or not around the globe enough), hadn't seen those. (You too ? Look at http://en.wikipedia.org/wiki/Verticon for the {^_^} ) --andersThink it was suggested before, but the language wasn't taking in any more operators at the time ? (The other one was ^^ for logical Xor.)Sure is kinda funny when we start using emoticons for operators... ^^
Nov 28 2006
Bruno Medeiros wrote:I don't understand the logic sequence between those two sentences: you say you don't know that emoticon, but then you should you do, and ask if I don't know the emoticon? ... Huh? Of course I know. Confusion ensues :P )Nah, I meant "if someone else needs to look it up, here's a link". As in someone reading it other than the original poster, i.e. you. Sorry for the confusion, it got pasted together... :-) ^_^ (-: --anders
Nov 28 2006
Bruno Medeiros wrote:Sure is kinda funny when we start using emoticons for operators... ^^I can't wait to see what kind of functionality can be provided using the Homer Simpson operator: ~(_8^(|) Maybe it can be some sort of exception-handling operator. D'oh!!! --benji
Nov 27 2006
Benji Smith wrote:Bruno Medeiros wrote:Oooo, make it a D easter egg?! <g>Sure is kinda funny when we start using emoticons for operators... ^^I can't wait to see what kind of functionality can be provided using the Homer Simpson operator: ~(_8^(|) Maybe it can be some sort of exception-handling operator. D'oh!!! --benji
Nov 27 2006
Kyle Furlong wrote: <snip>Oooo, make it a D easter egg?! <g>What's the point of hiding Easter eggs if we've already found them? Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Nov 28 2006
Stewart Gordon wrote:Kyle Furlong wrote: <snip>We (early adopters) hide easter eggs for the new converts of 1.0 and beyond.Oooo, make it a D easter egg?! <g>What's the point of hiding Easter eggs if we've already found them? Stewart.
Nov 28 2006