From: "duerst (Martin Dürst)" Date: 2013-12-18T19:16:06+09:00 Subject: [ruby-core:59180] [ruby-trunk - Feature #7511] short-circuiting logical implication operator Issue #7511 has been updated by duerst (Martin D��rst). rits (First Last) wrote: > logical implication is a core operation of boolean algebra, do you also need concrete examples for || ? Logical implication is actually NOT a core operation of Boolean algebra. There are two wikipedia articles about Boolean algebra, http://en.wikipedia.org/wiki/Boolean_algebra and http://en.wikipedia.org/wiki/Boolean_algebra_(structure). In both, and/or/not are the core operations. This corresponds well with the fact that these three operations are available in virtually any programming language. On the other hand, implication doesn't appear in the later article, and only appears in the section on propositional logic in the former article. This corresponds well with the fact that there are very few programming languages that have an implication operator. Actually, I have to admit that I don't know a single programming language with such an operator. Do you? > ok if you insist, lets say your code needs to perform some optional work but successfully, i.e. the existence of the method must imply it's successful execution. > > required_work && respond_to?(optional_work) => send(optional_work) How frequent are such examples? I'd guess they are very infrequent. Also, implication used as an operation isn't that easy to understand because common sense doesn't easily grok the fact that false can imply anything. And rewriting the above as required_work and (not respond_to?(optional_work) or send(optional_work)) isn't actually too difficult to understand: Either the object doesn't respond to 'optional_work', or the 'optional_work' method returns a trueish value. This gives the whole picture. On the other hand, reading "respond_to?(optional_work) => send(optional_work)" directly as "the existence of the method must imply it's successful execution" leaves the reader with the job of filling in "but if the method doesn't exist, we are still good". My guess is that these kinds of difficulties also contributed to the fact that virtually no programming language has such an operator. ---------------------------------------- Feature #7511: short-circuiting logical implication operator https://bugs.ruby-lang.org/issues/7511#change-43742 Author: rits (First Last) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: Target version: Next Major I find I need logical implication (will use => here) in boolean expressions fairly often and even though a => b is equivalent to !a || b, this substitute is more difficult to read and make sense of in long expressions -- http://bugs.ruby-lang.org/