digitalmars.D - Rationale for not allowing overload of && and ||?
- Joe Gauterin (1/1) Jun 18 2008 What is the rationale for not allowing overloading of && and ||? It seem...
- Nick Sabalausky (9/12) Jun 18 2008 If I'm not mistaken, I think you can define an "implicit conversion from...
- Brian Price (4/18) Jun 18 2008
- Nick Sabalausky (3/27) Jun 18 2008 I stand corrected :)
- Jarrett Billingsley (3/26) Jun 18 2008 & and |?
- Brian Price (3/34) Jun 18 2008 That is, of course, the workaround. However bitwise-and does not mean l...
- Joe Gauterin (2/39) Jun 23 2008 So there's no real reason? Presumably it's just a hangover from when D d...
- bearophile (12/13) Jun 18 2008 Maybe you are talking about the lazy or/and of languages like Python. I ...
- BCS (3/13) Jun 18 2008 || and && are lazy in D
- Jarrett Billingsley (3/16) Jun 18 2008 It returns the value instead of the value converted to a bool.
What is the rationale for not allowing overloading of && and ||? It seems to me that, with the 'lazy' keyword, D is one of the few languages where overloaded && and || can correctly implement short circuited evaluation.
Jun 18 2008
"Joe Gauterin" <Joseph.Gauterin googlemail.com> wrote in message news:g3bpl0$1ujc$1 digitalmars.com...What is the rationale for not allowing overloading of && and ||? It seems to me that, with the 'lazy' keyword, D is one of the few languages where overloaded && and || can correctly implement short circuited evaluation.If I'm not mistaken, I think you can define an "implicit conversion from this class (or struct?) to ...". So I assume the reason is, defining an implicit conversion to bool would effectively eliminate all (legitamate) reasons to overload && and ||. The only things that overloading && and || could do that couldn't be accomplished (with better compatability across various types) would be things that would break the intended meaning of && and ||. Buy that's considered bad style when overloading operators anyway.
Jun 18 2008
Nick Sabalausky Wrote:"Joe Gauterin" <Joseph.Gauterin googlemail.com> wrote in message news:g3bpl0$1ujc$1 digitalmars.com...Bayesian and fuzzy logic both assign non boolean meanings to the operations and/or. If you cannot overload && and || you cannot express such logic operations in a concise recognizable form. BrianWhat is the rationale for not allowing overloading of && and ||? It seems to me that, with the 'lazy' keyword, D is one of the few languages where overloaded && and || can correctly implement short circuited evaluation.If I'm not mistaken, I think you can define an "implicit conversion from this class (or struct?) to ...". So I assume the reason is, defining an implicit conversion to bool would effectively eliminate all (legitamate) reasons to overload && and ||. The only things that overloading && and || could do that couldn't be accomplished (with better compatability across various types) would be things that would break the intended meaning of && and ||. Buy that's considered bad style when overloading operators anyway.
Jun 18 2008
"Brian Price" <blprice61 yahoo.com> wrote in message news:g3brj5$2370$1 digitalmars.com...Nick Sabalausky Wrote:I stand corrected :)"Joe Gauterin" <Joseph.Gauterin googlemail.com> wrote in message news:g3bpl0$1ujc$1 digitalmars.com...Bayesian and fuzzy logic both assign non boolean meanings to the operations and/or. If you cannot overload && and || you cannot express such logic operations in a concise recognizable form. BrianWhat is the rationale for not allowing overloading of && and ||? It seems to me that, with the 'lazy' keyword, D is one of the few languages where overloaded && and || can correctly implement short circuited evaluation.If I'm not mistaken, I think you can define an "implicit conversion from this class (or struct?) to ...". So I assume the reason is, defining an implicit conversion to bool would effectively eliminate all (legitamate) reasons to overload && and ||. The only things that overloading && and || could do that couldn't be accomplished (with better compatability across various types) would be things that would break the intended meaning of && and ||. Buy that's considered bad style when overloading operators anyway.
Jun 18 2008
"Brian Price" <blprice61 yahoo.com> wrote in message news:g3brj5$2370$1 digitalmars.com...Nick Sabalausky Wrote:& and |?"Joe Gauterin" <Joseph.Gauterin googlemail.com> wrote in message news:g3bpl0$1ujc$1 digitalmars.com...Bayesian and fuzzy logic both assign non boolean meanings to the operations and/or. If you cannot overload && and || you cannot express such logic operations in a concise recognizable form.What is the rationale for not allowing overloading of && and ||? It seems to me that, with the 'lazy' keyword, D is one of the few languages where overloaded && and || can correctly implement short circuited evaluation.If I'm not mistaken, I think you can define an "implicit conversion from this class (or struct?) to ...". So I assume the reason is, defining an implicit conversion to bool would effectively eliminate all (legitamate) reasons to overload && and ||. The only things that overloading && and || could do that couldn't be accomplished (with better compatability across various types) would be things that would break the intended meaning of && and ||. Buy that's considered bad style when overloading operators anyway.
Jun 18 2008
Jarrett Billingsley Wrote:"Brian Price" <blprice61 yahoo.com> wrote in message news:g3brj5$2370$1 digitalmars.com...That is, of course, the workaround. However bitwise-and does not mean logical and, nor bitwise-or mean logical or, so you are forced to use a syntax that is semantically incorrect. That is, if you want the convenience of using operators. BrianNick Sabalausky Wrote:& and |?"Joe Gauterin" <Joseph.Gauterin googlemail.com> wrote in message news:g3bpl0$1ujc$1 digitalmars.com...Bayesian and fuzzy logic both assign non boolean meanings to the operations and/or. If you cannot overload && and || you cannot express such logic operations in a concise recognizable form.What is the rationale for not allowing overloading of && and ||? It seems to me that, with the 'lazy' keyword, D is one of the few languages where overloaded && and || can correctly implement short circuited evaluation.If I'm not mistaken, I think you can define an "implicit conversion from this class (or struct?) to ...". So I assume the reason is, defining an implicit conversion to bool would effectively eliminate all (legitamate) reasons to overload && and ||. The only things that overloading && and || could do that couldn't be accomplished (with better compatability across various types) would be things that would break the intended meaning of && and ||. Buy that's considered bad style when overloading operators anyway.
Jun 18 2008
Brian Price Wrote:Jarrett Billingsley Wrote:So there's no real reason? Presumably it's just a hangover from when D didn't have the 'lazy' keyword or an aversion to overloading them due to the mess C++ makes of it."Brian Price" <blprice61 yahoo.com> wrote in message news:g3brj5$2370$1 digitalmars.com...That is, of course, the workaround. However bitwise-and does not mean logical and, nor bitwise-or mean logical or, so you are forced to use a syntax that is semantically incorrect. That is, if you want the convenience of using operators. BrianNick Sabalausky Wrote:& and |?"Joe Gauterin" <Joseph.Gauterin googlemail.com> wrote in message news:g3bpl0$1ujc$1 digitalmars.com...Bayesian and fuzzy logic both assign non boolean meanings to the operations and/or. If you cannot overload && and || you cannot express such logic operations in a concise recognizable form.What is the rationale for not allowing overloading of && and ||? It seems to me that, with the 'lazy' keyword, D is one of the few languages where overloaded && and || can correctly implement short circuited evaluation.If I'm not mistaken, I think you can define an "implicit conversion from this class (or struct?) to ...". So I assume the reason is, defining an implicit conversion to bool would effectively eliminate all (legitamate) reasons to overload && and ||. The only things that overloading && and || could do that couldn't be accomplished (with better compatability across various types) would be things that would break the intended meaning of && and ||. Buy that's considered bad style when overloading operators anyway.
Jun 23 2008
Joe Gauterin Wrote:What is the rationale for not allowing overloading of && and ||? It seems to me that, with the 'lazy' keyword, D is one of the few languages where overloaded && and || can correctly implement short circuited evaluation.Maybe you are talking about the lazy or/and of languages like Python. I have created lazyAnd(), lazyOr() in my libs, and I think I like them more explicitly named, to avoid confusion. They are shaped like: Types[0] lazyAnd(Types...)(lazy Types items) { // some static asserts here to avoid some problems foreach (el; items[0 .. $-1]) if (not(el)) return el; return items[$-1]; } Where not() is a boolean that is true/false if the item is 0, 0.0, null, an empty array, an empty set, empty AA, something with length zero, etc etc. Bye, bearophile
Jun 18 2008
Reply to bearophile,Joe Gauterin Wrote:|| and && are lazy in D What does your provide that the native one don't?What is the rationale for not allowing overloading of && and ||? It seems to me that, with the 'lazy' keyword, D is one of the few languages where overloaded && and || can correctly implement short circuited evaluation.I have created lazyAnd(), lazyOr() in my libs, and I think I like them more explicitly named, to avoid confusion. They are shaped like:
Jun 18 2008
"BCS" <ao pathlink.com> wrote in message news:55391cb32e4e58ca9f630a69297e news.digitalmars.com...Reply to bearophile,It returns the value instead of the value converted to a bool.Joe Gauterin Wrote:|| and && are lazy in D What does your provide that the native one don't?What is the rationale for not allowing overloading of && and ||? It seems to me that, with the 'lazy' keyword, D is one of the few languages where overloaded && and || can correctly implement short circuited evaluation.I have created lazyAnd(), lazyOr() in my libs, and I think I like them more explicitly named, to avoid confusion. They are shaped like:
Jun 18 2008