digitalmars.D - Fun with opPos()
- Arcane Jill (8/8) Jul 29 2004 Well, now we have opPos() to complement opNeg(). We can overload the una...
- Juanjo =?ISO-8859-15?Q?=C1lvarez?= (4/16) Jul 29 2004 You can use it to put some random obfuscated and lengthy code to impress
- pragma (6/18) Jul 29 2004 Actually, this might be the answer Matthew was looking for since we cann...
- h3r3tic (6/18) Jul 29 2004 Let's think:
- Andy Friesen (6/17) Jul 29 2004 T opPos() { return opNeg(); }
- Norbert Nemec (3/21) Jul 29 2004 Walter makes it very clear in the specs that he is against that practice...
- Regan Heath (15/25) Jul 29 2004 Sorry for being serious'n'all but aren't opPos and opNeg perfectly usefu...
- Jarrett Billingsley (5/5) Jul 29 2004 *techincally* opPos returns the number. it's like multiplying by 1. it
- Regan Heath (11/17) Jul 29 2004 Thanks, I have never used opPos (operator+) nor have I used it on an int...
- Arcane Jill (10/20) Jul 30 2004 Clearly. (Sorry).
- Andy Friesen (4/15) Jul 29 2004 The most obvious thing in the world:
- Arcane Jill (3/5) Jul 30 2004 LOL. Excellent!
- Mike Parker (2/11) Jul 29 2004 char[] opPos() { return "The glass is half full" };
- Martin M. Pedersen (7/12) Jul 30 2004 plus
- J Anderson (24/32) Jul 30 2004 By "fun" I guess you mean something evil like:
-
Carlos Santander B.
(18/18)
Jul 31 2004
"Arcane Jill"
escribió en el mensaje - J Anderson (5/24) Jul 31 2004 opPlus implies that we are adding something. opPos means positive like
-
Carlos Santander B.
(19/19)
Jul 31 2004
"J Anderson"
escribió en el mensaje - James McComb (5/7) Jul 31 2004 It's not true that -x = -abs(x).
-
Carlos Santander B.
(16/16)
Aug 01 2004
"James McComb"
escribió en el mensaje - Arcane Jill (8/9) Aug 01 2004 I refute that accusation most ephatically. I am not that stupid. I said:...
- Andy Friesen (6/19) Aug 01 2004 On the plus side, (pun honestly not intended) it's probably more
-
Carlos Santander B.
(16/16)
Aug 01 2004
"Arcane Jill"
escribió en el mensaje - parabolis (3/16) Aug 01 2004 So what do you do with opMod() for a type that has not integer part?
- Sean Kelly (3/7) Aug 01 2004 Zero. Or perhaps the margin of error for floating point on type double.
- parabolis (3/15) Aug 01 2004 Double is zero, but then double can also represent integers:
- Arcane Jill (4/6) Aug 01 2004 0.2 (since 0.95 = 3 * 0.25 + 0.2)
- parabolis (2/7) Aug 01 2004 Yes I suppose you have a point.
- h3r3tic (2/5) Aug 01 2004 No way. fmod is already implemented -> www.fmod.org
- Nick (5/7) Aug 01 2004 It's 0.2, according to dmd ;-) It's defined as
- Sean Kelly (3/14) Aug 01 2004 Oops, yeah it does. Very nice.
Well, now we have opPos() to complement opNeg(). We can overload the unary plus operator. The obvious implementation is: (or .dup, or similar). But such trivial functions do seem a little pointless. What /else/ could we do with opPlus()? This is a non-serious thread, so humorous replies are welcome! Jill
Jul 29 2004
Arcane Jill wrote:Well, now we have opPos() to complement opNeg(). We can overload the unary plus operator. The obvious implementation is: (or .dup, or similar). But such trivial functions do seem a little pointless. What /else/ could we do with opPlus()? This is a non-serious thread, so humorous replies are welcome! JillYou can use it to put some random obfuscated and lengthy code to impress your boss and made him think you work a lot instead of reading the D newsgroups.
Jul 29 2004
In article <ceamke$1bfo$1 digitaldaemon.com>, Arcane Jill says...(or .dup, or similar). But such trivial functions do seem a little pointless. What /else/ could we do with opPlus()? This is a non-serious thread, so humorous replies are welcome! JillActually, this might be the answer Matthew was looking for since we cannot overload the pointer-to operator (*).class Boxed(T){ T value; this(T value){ this.value = value; } T opPos(){ return(this.value); } }In this way, opPos now returns the underlying value, which could be quite a boon for template programming as this helps objects look more like primitives.Boxed!(int) intBox = new Boxed!(int)(42); int fortyTwo = 42; assert(+intBox == +fortyTwo);- Pragma
Jul 29 2004
In article <ceavql$1ej2$1 digitaldaemon.com>, pragma <EricAnderton at yahoo dot com> says...Actually, this might be the answer Matthew was looking for since we cannot overload the pointer-to operator (*).Let's think: 1. it's barely readable 2. hmmm, ++ for double dereference ? by the way, why can't we overload the * unary operator ?class Boxed(T){ T value; this(T value){ this.value = value; } T opPos(){ return(this.value); } }In this way, opPos now returns the underlying value, which could be quite a boon for template programming as this helps objects look more like primitives.Boxed!(int) intBox = new Boxed!(int)(42); int fortyTwo = 42; assert(+intBox == +fortyTwo);
Jul 29 2004
Arcane Jill wrote:Well, now we have opPos() to complement opNeg(). We can overload the unary plus operator. The obvious implementation is: (or .dup, or similar). But such trivial functions do seem a little pointless. What /else/ could we do with opPlus()? This is a non-serious thread, so humorous replies are welcome!T opPos() { return opNeg(); } It also might be useful in situations where one wants to use overloaded operators to create syntax that resembles another language. (like how Boost.Spirit apes BNF to create parsers) -- andy
Jul 29 2004
Andy Friesen wrote:Arcane Jill wrote:Walter makes it very clear in the specs that he is against that practice. So be prepared for some major obstacles trying to follow that road...Well, now we have opPos() to complement opNeg(). We can overload the unary plus operator. The obvious implementation is: (or .dup, or similar). But such trivial functions do seem a little pointless. What /else/ could we do with opPlus()? This is a non-serious thread, so humorous replies are welcome!T opPos() { return opNeg(); } It also might be useful in situations where one wants to use overloaded operators to create syntax that resembles another language. (like how Boost.Spirit apes BNF to create parsers)
Jul 29 2004
Sorry for being serious'n'all but aren't opPos and opNeg perfectly useful if you're implementing something that can be positive or negative? Like your Int class Jill? eg. class SimpleInt { int value; SimpleInt opPos() { if (value < 0) value = -value; return this; } SimpleInt opNeg() { if (value > 0) value = -value; return this; } } or am I missing something? Regan On Thu, 29 Jul 2004 11:21:50 +0000 (UTC), Arcane Jill <Arcane_member pathlink.com> wrote:Well, now we have opPos() to complement opNeg(). We can overload the unary plus operator. The obvious implementation is: (or .dup, or similar). But such trivial functions do seem a little pointless. What /else/ could we do with opPlus()? This is a non-serious thread, so humorous replies are welcome! Jill-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 29 2004
*techincally* opPos returns the number. it's like multiplying by 1. it does nothing. but what you've just done is made it operate like abs(n) ;) also opNeg is like multiplying by -1, what you've done is like 0-abs(n). or we could overload opPos to do something horrible, like cause an access violation. or play some country music :o
Jul 29 2004
On Fri, 30 Jul 2004 00:59:06 -0400, Jarrett Billingsley <kb3ctd2 yahoo.com> wrote:*techincally* opPos returns the number. it's like multiplying by 1. it does nothing. but what you've just done is made it operate like abs(n) ;)Thanks, I have never used opPos (operator+) nor have I used it on an int or anything like that so I had no idea what it did. I assumed it did something useful. It appears to be useless?also opNeg is like multiplying by -1, what you've done is like 0-abs(n).Oops so I have, I should have realised that.or we could overload opPos to do something horrible, like cause an access violation. or play some country music :oIf it's as useless as it appears to me.. the only thing stopping you is the sheer lunacy of it. Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 29 2004
In article <opsbxhk9m95a2sq9 digitalmars.com>, Regan Heath says...Sorry for being serious'n'all but aren't opPos and opNeg perfectly useful if you're implementing something that can be positive or negative? Like your Int class Jill? eg. class SimpleInt { int value; SimpleInt opPos() { if (value < 0) value = -value; return this; } SimpleInt opNeg() { if (value > 0) value = -value; return this; } } or am I missing something?Clearly. (Sorry). I'd want x = -y; to assign x with minus y, not with -abs(y). If y is -3 then the statement x = -y; should (and will) result in (x == 3). And there is no way I'm going to change that. Int does provide the function abs(). In math, the main use for unary plus is to turn a double-valued result into a single-valued result. For instance sqrt(2) is double-valued, but +sqrt(2) is single-valued. It's hard to see how that could be useful in D. Jill
Jul 30 2004
Arcane Jill wrote:Well, now we have opPos() to complement opNeg(). We can overload the unary plus operator. The obvious implementation is: (or .dup, or similar). But such trivial functions do seem a little pointless. What /else/ could we do with opPlus()? This is a non-serious thread, so humorous replies are welcome!The most obvious thing in the world: void opPos() { this += 0.5; } -- andy
Jul 29 2004
In article <cecmgc$26dk$1 digitaldaemon.com>, Andy Friesen says...The most obvious thing in the world: void opPos() { this += 0.5; }LOL. Excellent! Jill
Jul 30 2004
Arcane Jill wrote:Well, now we have opPos() to complement opNeg(). We can overload the unary plus operator. The obvious implementation is: (or .dup, or similar). But such trivial functions do seem a little pointless. What /else/ could we do with opPlus()?char[] opPos() { return "The glass is half full" };
Jul 29 2004
"Arcane Jill" <Arcane_member pathlink.com> skrev i en meddelelse news:ceamke$1bfo$1 digitaldaemon.com...Well, now we have opPos() to complement opNeg(). We can overload the unaryplusoperator. (or .dup, or similar). But such trivial functions do seem a littlepointless.What /else/ could we do with opPlus()? This is a non-serious thread, so humorous replies are welcome!It is an obvious candidate for hiding easter eggs in libraries. Regards, Martin M. Pedersen
Jul 30 2004
Arcane Jill wrote:Well, now we have opPos() to complement opNeg(). We can overload the unary plus operator. The obvious implementation is: (or .dup, or similar). But such trivial functions do seem a little pointless. What /else/ could we do with opPlus()? This is a non-serious thread, so humorous replies are welcome! JillBy "fun" I guess you mean something evil like: struct Test { Test opPos() { printf("+\n"); return *this; } Test opNeg() { printf("-\n"); return *this; } } void main() { Test t; + - + + +t; } I guess it could have all kinds of evil-non-mathematical uses. -- -Anderson: http://badmama.com.au/~anderson/
Jul 30 2004
"Arcane Jill" <Arcane_member pathlink.com> escribió en el mensaje news:ceamke$1bfo$1 digitaldaemon.com | Well, now we have opPos() to complement opNeg(). We can overload the unary plus | operator. | | The obvious implementation is: | | | (or .dup, or similar). But such trivial functions do seem a little pointless. | What /else/ could we do with opPlus()? | | This is a non-serious thread, so humorous replies are welcome! | Jill Why is it opPos? Shouldn't it be opUnaryPlus, or even opPlus? ----------------------- Carlos Santander Bernal
Jul 31 2004
Carlos Santander B. wrote:"Arcane Jill" <Arcane_member pathlink.com> escribió en el mensaje news:ceamke$1bfo$1 digitaldaemon.com | Well, now we have opPos() to complement opNeg(). We can overload the unary plus | operator. | | The obvious implementation is: | | | (or .dup, or similar). But such trivial functions do seem a little pointless. | What /else/ could we do with opPlus()? | | This is a non-serious thread, so humorous replies are welcome! | Jill Why is it opPos? Shouldn't it be opUnaryPlus, or even opPlus? ----------------------- Carlos Santander BernalopPlus implies that we are adding something. opPos means positive like opNeg means negative. -- -Anderson: http://badmama.com.au/~anderson/
Jul 31 2004
"J Anderson" <REMOVEanderson badmama.com.au> escribió en el mensaje news:cegcuo$13du$1 digitaldaemon.com | Carlos Santander B. wrote: || Why is it opPos? Shouldn't it be opUnaryPlus, or even opPlus? || || ----------------------- || Carlos Santander Bernal || || || | opPlus implies that we are adding something. opPos means positive like | opNeg means negative. | | -- | -Anderson: http://badmama.com.au/~anderson/ But as Jill already pointed: +x = x, -x = -abs(x). (mathematically speaking), so it's not positive: it's the same ----------------------- Carlos Santander Bernal
Jul 31 2004
Carlos Santander B. wrote:But as Jill already pointed: +x = x, -x = -abs(x). (mathematically speaking), so it's not positive: it's the sameIt's not true that -x = -abs(x). If x = -5, then -x = 5, but -abs(x) = -5. WHAT AN IMPORTANT RESULT! ;) James McComb
Jul 31 2004
"James McComb" <alan jamesmccomb.id.au> escribió en el mensaje news:cehlgr$1ju0$1 digitaldaemon.com | It's not true that -x = -abs(x). | | If x = -5, then -x = 5, but -abs(x) = -5. | | WHAT AN IMPORTANT RESULT! ;) | | James McComb (where do I hide, where do I hide????) Yes, sorry, my mistake. But I still think opPos is not the right name, for the same reason that +x != abs(x). But I won't argue for that anymore. (and to think that until a couple of years ago I was a very good mathemathician...) ----------------------- Carlos Santander Bernal
Aug 01 2004
In article <cegg4j$14ng$1 digitaldaemon.com>, Carlos Santander B. says...But as Jill already pointed: ... -x = -abs(x).I refute that accusation most ephatically. I am not that stupid. I said: "I'd want x = -y; to assign x with minus y, not with -abs(y).". Misquotation is one thing; misquotation in a way which impunes my intelligence is quite another. By the way, regarding your recent discussions on the name opPos(), are you guys /seriously/ arguing over the name of a function whose only reasonable implementation is to do absolutely nothing whatsoever? Jill
Aug 01 2004
Arcane Jill wrote:In article <cegg4j$14ng$1 digitaldaemon.com>, Carlos Santander B. says...On the plus side, (pun honestly not intended) it's probably more important that we can define it at all, just so that the compiler will allow something that otherwise looks like a number to behave like one in this respect as well. -- andyBut as Jill already pointed: ... -x = -abs(x).I refute that accusation most ephatically. I am not that stupid. I said: "I'd want x = -y; to assign x with minus y, not with -abs(y).". Misquotation is one thing; misquotation in a way which impunes my intelligence is quite another. By the way, regarding your recent discussions on the name opPos(), are you guys /seriously/ arguing over the name of a function whose only reasonable implementation is to do absolutely nothing whatsoever?
Aug 01 2004
"Arcane Jill" <Arcane_member pathlink.com> escribió en el mensaje news:ceiv8s$24lj$1 digitaldaemon.com | I refute that accusation most ephatically. I am not that stupid. I said: "I'd | want x = -y; to assign x with minus y, not with -abs(y).". Misquotation is one | thing; misquotation in a way which impunes my intelligence is quite another. | I already admitted mistake. Sorry for any involving you in my lack of focus. | By the way, regarding your recent discussions on the name opPos(), are you guys | /seriously/ arguing over the name of a function whose only reasonable | implementation is to do absolutely nothing whatsoever? | | Jill Yes, I gave up on that too. ----------------------- Carlos Santander Bernal
Aug 01 2004
Arcane Jill wrote:Well, now we have opPos() to complement opNeg(). We can overload the unary plus operator. The obvious implementation is: (or .dup, or similar). But such trivial functions do seem a little pointless. What /else/ could we do with opPlus()? This is a non-serious thread, so humorous replies are welcome! JillSo what do you do with opMod() for a type that has not integer part? What is 0.95 % 0.25?
Aug 01 2004
parabolis wrote:So what do you do with opMod() for a type that has not integer part? What is 0.95 % 0.25?Zero. Or perhaps the margin of error for floating point on type double. Sean
Aug 01 2004
Sean Kelly wrote:parabolis wrote:Double is zero, but then double can also represent integers: 13.0 % 5.0 == 3.0...So what do you do with opMod() for a type that has not integer part? What is 0.95 % 0.25?Zero. Or perhaps the margin of error for floating point on type double. Sean
Aug 01 2004
In article <cejim8$2c3n$1 digitaldaemon.com>, parabolis says...So what do you do with opMod() for a type that has not integer part?I'd implement fmod().What is 0.95 % 0.25?0.2 (since 0.95 = 3 * 0.25 + 0.2) Arcane Jill
Aug 01 2004
Arcane Jill wrote:Yes I suppose you have a point.What is 0.95 % 0.25?0.2 (since 0.95 = 3 * 0.25 + 0.2)
Aug 01 2004
Arcane Jill wrote:In article <cejim8$2c3n$1 digitaldaemon.com>, parabolis says...No way. fmod is already implemented -> www.fmod.orgSo what do you do with opMod() for a type that has not integer part?I'd implement fmod().
Aug 01 2004
In article <cejim8$2c3n$1 digitaldaemon.com>, parabolis says...So what do you do with opMod() for a type that has not integer part? What is 0.95 % 0.25?It's 0.2, according to dmd ;-) It's defined as a % b = a - floor(a/b) * b It makes sense when you think about it. Nick
Aug 01 2004
Nick wrote:In article <cejim8$2c3n$1 digitaldaemon.com>, parabolis says...Oops, yeah it does. Very nice. SeanSo what do you do with opMod() for a type that has not integer part? What is 0.95 % 0.25?It's 0.2, according to dmd ;-) It's defined as a % b = a - floor(a/b) * b It makes sense when you think about it.
Aug 01 2004