From: "jEFF (Jean-François Berroyer)" Date: 2012-06-15T19:57:57+09:00 Subject: [ruby-core:45665] [ruby-trunk - Feature #6555] New comparison operators Issue #6555 has been updated by jEFF (Jean-Fran��ois Berroyer). =begin A friend told me that D language provides 14 comparisons operators for Floating point comparisons : (()) I don't know how really useful it is in D, but it is interesting because that is the same problem. jEFF =end ---------------------------------------- Feature #6555: New comparison operators https://bugs.ruby-lang.org/issues/6555#change-27264 Author: jEFF (Jean-Fran��ois Berroyer) Status: Open Priority: Normal Assignee: Category: core Target version: 2.0.0 =begin x <=> y returns -1, 0, 1 or nil (x <=> y) == -1 means "x less than y" and is the same as x < y (x <=> y) == 0 means "x equal y" is the same as x == y (x <=> y) == 1 means "x greater than y" and is the same as x > y (x <=> y) == nil means "x not comparable with y" and is the same as !(x <=> y) We see there is no short syntax to test if two objects are not comparable. Can we have something like (({x >< y})), provided by (({Comparable})) module, that would mean "x and y are not comparable" ? As (({x != y})) is a short syntax for (({!(x == y)})), can we have (({x !< y})) for (({!(x < y)})) and (({x !<= y})) for (({!(x <= y)})) and so on ? As (({x <= y})) is the same as (({(x < y or x == y)})), can we have (({x <> y})) for (({(x < y or x > y)})) ? Here is a list of all possible comparison operators there could be (and their meanings) : < return true when <=> return -1 ("less than") == return true when <=> return 0 ("egal") > return true when <=> return 1 ("greater than") <= return true when <=> return -1 or 0 ("equal or less than") >= return true when <=> return 1 or 0 ("equal or greater than") <> return true when <=> return 1 or -1 ("less or greater than" that is to say "comparable and different") >< return true when <=> return nil ("not comparable") !< return true when <=> return 0 or 1 or nil ("not less than", that is different from "greater than or eqal" that involves "comparable") != return true when <=> return -1 or 1 or nil ("not equal", that is different from "less or greater than" that involves "comparable") !> return true when <=> return -1 or 0 or nil ("not greater than", that is different from "less than or eqal" that involves "comparable") !<= return true when <=> return nil or 1 ("not equal nor less than", that is different from "greater than" that involves "comparable") !>= return true when <=> return nil or -1 ("not equal nor greater than", that is different from "less than" that involves "comparable") !<> return true when <=> return 0 or nil ("not less nor greater than", that is different from "egal" that involves "comparable") !>< return true when <=> return -1 or 0 or 1 ("not not comparable" or just "comparable", the same as <=> but returning a boolean) All these operators would be very useful, especially when working with partial orders (like subset-inclusion for exemple). Perhaps (({x !== y})) should also be a short syntax for (({!(x === y)})). =end -- http://bugs.ruby-lang.org/