[#111712] [Ruby master Feature#19322] Support spawning "private" child processes — "kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core" <ruby-core@...>
SXNzdWUgIzE5MzIyIGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGtqdHNhbmFrdHNpZGlzIChLSiBUc2Fu
14 messages
2023/01/07
[ruby-core:111562] [Ruby master Feature#16995] Sets: <=> should be specialized
From:
"zverok (Victor Shepelev) via ruby-core" <ruby-core@...>
Date:
2023-01-01 13:04:53 UTC
List:
ruby-core #111562
Issue #16995 has been updated by zverok (Victor Shepelev).
Status changed from Open to Closed
Implemented in Ruby 3.0:
```ruby
Set[1] <=> Set[1, 2]
# => -1
[Set[1], Set[1, 2]].sort
# => [#<Set: {1}>, #<Set: {1, 2}>]
```
----------------------------------------
Feature #16995: Sets: <=> should be specialized
https://bugs.ruby-lang.org/issues/16995#change-100927
* Author: marcandre (Marc-Andre Lafortune)
* Status: Closed
* Priority: Normal
----------------------------------------
This is quite minor, but `Set#<=>` should be refined.
Reminder: `Set` defines `<`, `>`, etc. as inclusion, but does not have a corresponding `<=>`:
```ruby
Set[1] < Set[1, 2] # => true
Set[1] <=> Set[1, 2] # => nil, should be -1
Set[1] <=> Set[2] # => nil, ok, not orderable
```
The official stated reason for `Set` to *not* implement is that some sets are not comparable. That is exactly what `nil` result type is for IMO. Sets are partically ordered and `<=>` should reflect that. https://en.wikipedia.org/wiki/Partially_ordered_set
```ruby
Set[1] < Set[1, 2] # => true
[Set[1], Set[1, 2]].sort # => ArgumentError, should be [Set[1], Set[1, 2]]
[Set[1], Set[2]].sort # => ArgumentError, ok, can't be ordered
```
This is *exactly the same* idea as `Class`, which correctly refines `<=>`:
```ruby
Array < Enumerable # => true
Array <=> Enumerable # => -1, ok
[Array, Enumerable].sort # => [Array, Enumerable]
[Array, String].sort # => ArgumentError (comparison of Class with Class failed), ok
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/