Issue #14951 has been updated by danga (Dan Garubba).


Thanks. Essentially, this helper is a form of the boolean singleton normalization I apply at the application level. 

I understand there should be a high threshold for introducing new operators into a language, so I wanted to see if anyone else felt as strongly about logical equivalence as I had. Ruby has looser boolean conventions for return values than other popular languages. Because of that, using `==` to test for logical equivalence has pitfalls that I didn't appreciate until I stumbled into the gotcha of my example. I was thinking a new operator would serve as a best practice to avoid such pitfalls and expresses the "don't care about the specific boolean type" style to the language, but the strong need probably isn't there.

----------------------------------------
Feature #14951: New operator to evaluate truthy/falsy/logical equivalence
https://bugs.ruby-lang.org/issues/14951#change-73245

* Author: danga (Dan Garubba)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I propose adding a new operator for truthy/falsy equivalence, similar to what was proposed on https://bugs.ruby-lang.org/issues/13067, but with new syntax. The main purpose would be for writing expressions for logical equivalence (i.e., "if and only if" relationships) that only considers the truthiness the operands. Since predicate methods like `File#size?` and operators like `=~` follow truthy semantics without returning the `true` and `false` singletons, using them in logical expressions that evaluate for logical equivalence can be error-prone without the proper return type awareness and conversions. This proposed operator would be equivalent to `!!a == !!b`, but I feel that a new operator would be more concise and more expressive of the concept of logical equivalence.

Attached is a prototype implementation of the operator as '=?'.
 

---Files--------------------------------
teq.patch (3.47 KB)


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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>