[ruby-core:66654] [ruby-trunk - Feature #7511] short-circuiting logical implication operator

From: bigbadmath@...
Date: 2014-12-03 03:32:45 UTC
List: ruby-core #66654
Issue #7511 has been updated by Alexander Moore-Niemi.


to be precise, implies is a derived operator, not a core one.

eiffel supplies this operator to, afaik, help make design by contract easier (targeting assertions as a core responsibility of the language)

but given ruby has not committed to that, this would probably make more sense to recommend to https://github.com/egonSchiele/contracts.ruby library :)

racket also has the operator

in the meantime consider just refining TrueClass and FalseClass to receive a custom defined xnor if you want to be able to readably infix your predicates, ie.

~~~
2.1.3 :053 > false.class
 => FalseClass
2.1.3 :054 > class FalseClass
2.1.3 :055?>   def xnor(q)
2.1.3 :056?>       not self or q
2.1.3 :057?>     end
2.1.3 :058?>   end
 => :xnor
2.1.3 :059 > false.class
 => FalseClass
2.1.3 :060 > false.respond_to?(:xnor)
~~~

then you could do p.xnor(q) which i think is more readable than using the other recommended method

----------------------------------------
Feature #7511: short-circuiting logical implication operator
https://bugs.ruby-lang.org/issues/7511#change-50264

* Author: First Last
* Status: Assigned
* Priority: Normal
* Assignee: 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





-- 
https://bugs.ruby-lang.org/

In This Thread