* [ruby-core:113180] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification
@ 2023-04-11 0:58 kyanagi (Kouhei Yanagita) via ruby-core
2023-04-11 6:11 ` [ruby-core:113184] " sawa (Tsuyoshi Sawada) via ruby-core
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: kyanagi (Kouhei Yanagita) via ruby-core @ 2023-04-11 0:58 UTC (permalink / raw
To: ruby-core; +Cc: kyanagi (Kouhei Yanagita)
Issue #19588 has been reported by kyanagi (Kouhei Yanagita).
----------------------------------------
Feature #19588: Allow Comparable#clamp(min, max) to accept nil as a specification
https://bugs.ruby-lang.org/issues/19588
* Author: kyanagi (Kouhei Yanagita)
* Status: Open
* Priority: Normal
----------------------------------------
`Comparable#clamp(min, max)` (with two arguments) accepts `nil`. This behaves the same as beginless/endless Range.
~~~ruby
5.clamp(nil, 0) # => 0
5.clamp(10, nil) # => 10
5.clamp(..0) # => 0
5.clamp(10..) # => 10
~~~
This behavior is not documented. Presumably, this was not introduced intentionally.
The old Rubies did not accept accept a `Range` argument.
In Ruby 2.7, accepting `Range` as an argument was introduced.
At that time, the approach of passing `nil` as a two-argument method was also discussed but not adopted,
and using Range was chosen instead. https://bugs.ruby-lang.org/issues/14784
However, in Ruby 3.0, the behavior of `clamp` has changed to accept `nil`.
This change is not documented in the NEWS or the documentation for `clamp`,
and I believe that it was not an intentional change.
~~~
% docker run -it --rm rubylang/all-ruby env ALL_RUBY_SINCE=ruby-2.4.0 ./all-ruby -e "p 5.clamp(0, nil)"
ruby-2.4.0 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
...
ruby-2.7.8 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
ruby-3.0.0-preview1 5
...
ruby-3.2.2 5
~~~
It seems that https://github.com/ruby/ruby/commit/a93da4970be44a473b7b42e7516eb2663dece2c3 brought about this change.
How about making the current behavior a specification?
It has been three years since the behavior changed, and I don't see much point in prohibiting `nil` now.
--
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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:113184] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification
2023-04-11 0:58 [ruby-core:113180] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification kyanagi (Kouhei Yanagita) via ruby-core
@ 2023-04-11 6:11 ` sawa (Tsuyoshi Sawada) via ruby-core
2023-04-11 6:26 ` [ruby-core:113185] " sawa (Tsuyoshi Sawada) via ruby-core
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: sawa (Tsuyoshi Sawada) via ruby-core @ 2023-04-11 6:11 UTC (permalink / raw
To: ruby-core; +Cc: sawa (Tsuyoshi Sawada)
Issue #19588 has been updated by sawa (Tsuyoshi Sawada).
Currently, `clamp` accepts `min` and `max` simultaneously being `nil`. I think it should be synchronized with whether `(nil..nil).include?(foo)`is accepted or not. Cf. #19533.
----------------------------------------
Feature #19588: Allow Comparable#clamp(min, max) to accept nil as a specification
https://bugs.ruby-lang.org/issues/19588#change-102722
* Author: kyanagi (Kouhei Yanagita)
* Status: Open
* Priority: Normal
----------------------------------------
`Comparable#clamp(min, max)` (with two arguments) accepts `nil`. This behaves the same as beginless/endless Range.
~~~ruby
5.clamp(nil, 0) # => 0
5.clamp(10, nil) # => 10
5.clamp(..0) # => 0
5.clamp(10..) # => 10
~~~
This behavior is not documented. Presumably, this was not introduced intentionally.
The old Rubies did not accept accept a `Range` argument.
In Ruby 2.7, accepting `Range` as an argument was introduced.
At that time, the approach of passing `nil` as a two-argument method was also discussed but not adopted,
and using Range was chosen instead. https://bugs.ruby-lang.org/issues/14784
However, in Ruby 3.0, the behavior of `clamp` has changed to accept `nil`.
This change is not documented in the NEWS or the documentation for `clamp`,
and I believe that it was not an intentional change.
~~~
% docker run -it --rm rubylang/all-ruby env ALL_RUBY_SINCE=ruby-2.4.0 ./all-ruby -e "p 5.clamp(0, nil)"
ruby-2.4.0 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
...
ruby-2.7.8 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
ruby-3.0.0-preview1 5
...
ruby-3.2.2 5
~~~
It seems that https://github.com/ruby/ruby/commit/a93da4970be44a473b7b42e7516eb2663dece2c3 brought about this change.
How about making the current behavior a specification?
It has been three years since the behavior changed, and I don't see much point in prohibiting `nil` now.
--
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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:113185] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification
2023-04-11 0:58 [ruby-core:113180] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification kyanagi (Kouhei Yanagita) via ruby-core
2023-04-11 6:11 ` [ruby-core:113184] " sawa (Tsuyoshi Sawada) via ruby-core
@ 2023-04-11 6:26 ` sawa (Tsuyoshi Sawada) via ruby-core
2023-04-14 1:17 ` [ruby-core:113233] " mame (Yusuke Endoh) via ruby-core
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: sawa (Tsuyoshi Sawada) via ruby-core @ 2023-04-11 6:26 UTC (permalink / raw
To: ruby-core; +Cc: sawa (Tsuyoshi Sawada)
Issue #19588 has been updated by sawa (Tsuyoshi Sawada).
I think it is a good idea. It should be synchronized with `Range#cover?`.
----------------------------------------
Feature #19588: Allow Comparable#clamp(min, max) to accept nil as a specification
https://bugs.ruby-lang.org/issues/19588#change-102723
* Author: kyanagi (Kouhei Yanagita)
* Status: Open
* Priority: Normal
----------------------------------------
`Comparable#clamp(min, max)` (with two arguments) accepts `nil`. This behaves the same as beginless/endless Range.
~~~ruby
5.clamp(nil, 0) # => 0
5.clamp(10, nil) # => 10
5.clamp(..0) # => 0
5.clamp(10..) # => 10
~~~
This behavior is not documented. Presumably, this was not introduced intentionally.
The old Rubies did not accept accept a `Range` argument.
In Ruby 2.7, accepting `Range` as an argument was introduced.
At that time, the approach of passing `nil` as a two-argument method was also discussed but not adopted,
and using Range was chosen instead. https://bugs.ruby-lang.org/issues/14784
However, in Ruby 3.0, the behavior of `clamp` has changed to accept `nil`.
This change is not documented in the NEWS or the documentation for `clamp`,
and I believe that it was not an intentional change.
~~~
% docker run -it --rm rubylang/all-ruby env ALL_RUBY_SINCE=ruby-2.4.0 ./all-ruby -e "p 5.clamp(0, nil)"
ruby-2.4.0 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
...
ruby-2.7.8 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
ruby-3.0.0-preview1 5
...
ruby-3.2.2 5
~~~
It seems that https://github.com/ruby/ruby/commit/a93da4970be44a473b7b42e7516eb2663dece2c3 brought about this change.
How about making the current behavior a specification?
It has been three years since the behavior changed, and I don't see much point in prohibiting `nil` now.
--
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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:113233] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification
2023-04-11 0:58 [ruby-core:113180] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification kyanagi (Kouhei Yanagita) via ruby-core
2023-04-11 6:11 ` [ruby-core:113184] " sawa (Tsuyoshi Sawada) via ruby-core
2023-04-11 6:26 ` [ruby-core:113185] " sawa (Tsuyoshi Sawada) via ruby-core
@ 2023-04-14 1:17 ` mame (Yusuke Endoh) via ruby-core
2023-04-26 1:40 ` [ruby-core:113344] " kyanagi (Kouhei Yanagita) via ruby-core
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2023-04-14 1:17 UTC (permalink / raw
To: ruby-core; +Cc: mame (Yusuke Endoh)
Issue #19588 has been updated by mame (Yusuke Endoh).
Discussed at the dev meeting. @matz confirmed the behavior as is, so the proposed documentation change is accepted.
----------------------------------------
Feature #19588: Allow Comparable#clamp(min, max) to accept nil as a specification
https://bugs.ruby-lang.org/issues/19588#change-102780
* Author: kyanagi (Kouhei Yanagita)
* Status: Open
* Priority: Normal
----------------------------------------
`Comparable#clamp(min, max)` (with two arguments) accepts `nil`. This behaves the same as beginless/endless Range.
~~~ruby
5.clamp(nil, 0) # => 0
5.clamp(10, nil) # => 10
5.clamp(..0) # => 0
5.clamp(10..) # => 10
~~~
This behavior is not documented. Presumably, this was not introduced intentionally.
The old Rubies did not accept accept a `Range` argument.
In Ruby 2.7, accepting `Range` as an argument was introduced.
At that time, the approach of passing `nil` as a two-argument method was also discussed but not adopted,
and using Range was chosen instead. https://bugs.ruby-lang.org/issues/14784
However, in Ruby 3.0, the behavior of `clamp` has changed to accept `nil`.
This change is not documented in the NEWS or the documentation for `clamp`,
and I believe that it was not an intentional change.
~~~
% docker run -it --rm rubylang/all-ruby env ALL_RUBY_SINCE=ruby-2.4.0 ./all-ruby -e "p 5.clamp(0, nil)"
ruby-2.4.0 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
...
ruby-2.7.8 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
ruby-3.0.0-preview1 5
...
ruby-3.2.2 5
~~~
It seems that https://github.com/ruby/ruby/commit/a93da4970be44a473b7b42e7516eb2663dece2c3 brought about this change.
How about making the current behavior a specification?
It has been three years since the behavior changed, and I don't see much point in prohibiting `nil` now.
https://github.com/ruby/ruby/pull/7692 updates the documentation.
--
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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:113344] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification
2023-04-11 0:58 [ruby-core:113180] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification kyanagi (Kouhei Yanagita) via ruby-core
` (2 preceding siblings ...)
2023-04-14 1:17 ` [ruby-core:113233] " mame (Yusuke Endoh) via ruby-core
@ 2023-04-26 1:40 ` kyanagi (Kouhei Yanagita) via ruby-core
2023-10-10 4:52 ` [ruby-core:114989] " kyanagi (Kouhei Yanagita) via ruby-core
2023-11-30 6:19 ` [ruby-core:115535] " mame (Yusuke Endoh) via ruby-core
5 siblings, 0 replies; 7+ messages in thread
From: kyanagi (Kouhei Yanagita) via ruby-core @ 2023-04-26 1:40 UTC (permalink / raw
To: ruby-core; +Cc: kyanagi (Kouhei Yanagita)
Issue #19588 has been updated by kyanagi (Kouhei Yanagita).
The Japanese manual is updated.
https://docs.ruby-lang.org/ja/latest/class/Comparable.html#I_CLAMP
https://github.com/rurema/doctree/pull/2801
----------------------------------------
Feature #19588: Allow Comparable#clamp(min, max) to accept nil as a specification
https://bugs.ruby-lang.org/issues/19588#change-102904
* Author: kyanagi (Kouhei Yanagita)
* Status: Open
* Priority: Normal
----------------------------------------
`Comparable#clamp(min, max)` (with two arguments) accepts `nil`. This behaves the same as beginless/endless Range.
~~~ruby
5.clamp(nil, 0) # => 0
5.clamp(10, nil) # => 10
5.clamp(..0) # => 0
5.clamp(10..) # => 10
~~~
This behavior is not documented. Presumably, this was not introduced intentionally.
The old Rubies did not accept accept a `Range` argument.
In Ruby 2.7, accepting `Range` as an argument was introduced.
At that time, the approach of passing `nil` as a two-argument method was also discussed but not adopted,
and using Range was chosen instead. https://bugs.ruby-lang.org/issues/14784
However, in Ruby 3.0, the behavior of `clamp` has changed to accept `nil`.
This change is not documented in the NEWS or the documentation for `clamp`,
and I believe that it was not an intentional change.
~~~
% docker run -it --rm rubylang/all-ruby env ALL_RUBY_SINCE=ruby-2.4.0 ./all-ruby -e "p 5.clamp(0, nil)"
ruby-2.4.0 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
...
ruby-2.7.8 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
ruby-3.0.0-preview1 5
...
ruby-3.2.2 5
~~~
It seems that https://github.com/ruby/ruby/commit/a93da4970be44a473b7b42e7516eb2663dece2c3 brought about this change.
How about making the current behavior a specification?
It has been three years since the behavior changed, and I don't see much point in prohibiting `nil` now.
https://github.com/ruby/ruby/pull/7692 updates the documentation.
--
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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:114989] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification
2023-04-11 0:58 [ruby-core:113180] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification kyanagi (Kouhei Yanagita) via ruby-core
` (3 preceding siblings ...)
2023-04-26 1:40 ` [ruby-core:113344] " kyanagi (Kouhei Yanagita) via ruby-core
@ 2023-10-10 4:52 ` kyanagi (Kouhei Yanagita) via ruby-core
2023-11-30 6:19 ` [ruby-core:115535] " mame (Yusuke Endoh) via ruby-core
5 siblings, 0 replies; 7+ messages in thread
From: kyanagi (Kouhei Yanagita) via ruby-core @ 2023-10-10 4:52 UTC (permalink / raw
To: ruby-core; +Cc: kyanagi (Kouhei Yanagita)
Issue #19588 has been updated by kyanagi (Kouhei Yanagita).
If possible, could you merge the document and test update?
https://github.com/ruby/ruby/pull/7759
https://github.com/ruby/ruby/pull/7692
----------------------------------------
Feature #19588: Allow Comparable#clamp(min, max) to accept nil as a specification
https://bugs.ruby-lang.org/issues/19588#change-104859
* Author: kyanagi (Kouhei Yanagita)
* Status: Open
* Priority: Normal
----------------------------------------
`Comparable#clamp(min, max)` (with two arguments) accepts `nil`. This behaves the same as beginless/endless Range.
~~~ruby
5.clamp(nil, 0) # => 0
5.clamp(10, nil) # => 10
5.clamp(..0) # => 0
5.clamp(10..) # => 10
~~~
This behavior is not documented. Presumably, this was not introduced intentionally.
The old Rubies did not accept accept a `Range` argument.
In Ruby 2.7, accepting `Range` as an argument was introduced.
At that time, the approach of passing `nil` as a two-argument method was also discussed but not adopted,
and using Range was chosen instead. https://bugs.ruby-lang.org/issues/14784
However, in Ruby 3.0, the behavior of `clamp` has changed to accept `nil`.
This change is not documented in the NEWS or the documentation for `clamp`,
and I believe that it was not an intentional change.
~~~
% docker run -it --rm rubylang/all-ruby env ALL_RUBY_SINCE=ruby-2.4.0 ./all-ruby -e "p 5.clamp(0, nil)"
ruby-2.4.0 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
...
ruby-2.7.8 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
ruby-3.0.0-preview1 5
...
ruby-3.2.2 5
~~~
It seems that https://github.com/ruby/ruby/commit/a93da4970be44a473b7b42e7516eb2663dece2c3 brought about this change.
How about making the current behavior a specification?
It has been three years since the behavior changed, and I don't see much point in prohibiting `nil` now.
https://github.com/ruby/ruby/pull/7692 updates the documentation.
--
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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:115535] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification
2023-04-11 0:58 [ruby-core:113180] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification kyanagi (Kouhei Yanagita) via ruby-core
` (4 preceding siblings ...)
2023-10-10 4:52 ` [ruby-core:114989] " kyanagi (Kouhei Yanagita) via ruby-core
@ 2023-11-30 6:19 ` mame (Yusuke Endoh) via ruby-core
5 siblings, 0 replies; 7+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2023-11-30 6:19 UTC (permalink / raw
To: ruby-core; +Cc: mame (Yusuke Endoh)
Issue #19588 has been updated by mame (Yusuke Endoh).
Status changed from Open to Closed
The two PRs are merged. Closing
----------------------------------------
Feature #19588: Allow Comparable#clamp(min, max) to accept nil as a specification
https://bugs.ruby-lang.org/issues/19588#change-105470
* Author: kyanagi (Kouhei Yanagita)
* Status: Closed
* Priority: Normal
----------------------------------------
`Comparable#clamp(min, max)` (with two arguments) accepts `nil`. This behaves the same as beginless/endless Range.
~~~ruby
5.clamp(nil, 0) # => 0
5.clamp(10, nil) # => 10
5.clamp(..0) # => 0
5.clamp(10..) # => 10
~~~
This behavior is not documented. Presumably, this was not introduced intentionally.
The old Rubies did not accept accept a `Range` argument.
In Ruby 2.7, accepting `Range` as an argument was introduced.
At that time, the approach of passing `nil` as a two-argument method was also discussed but not adopted,
and using Range was chosen instead. https://bugs.ruby-lang.org/issues/14784
However, in Ruby 3.0, the behavior of `clamp` has changed to accept `nil`.
This change is not documented in the NEWS or the documentation for `clamp`,
and I believe that it was not an intentional change.
~~~
% docker run -it --rm rubylang/all-ruby env ALL_RUBY_SINCE=ruby-2.4.0 ./all-ruby -e "p 5.clamp(0, nil)"
ruby-2.4.0 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
...
ruby-2.7.8 -e:1:in `clamp': comparison of Integer with nil failed (ArgumentError)
from -e:1:in `<main>'
exit 1
ruby-3.0.0-preview1 5
...
ruby-3.2.2 5
~~~
It seems that https://github.com/ruby/ruby/commit/a93da4970be44a473b7b42e7516eb2663dece2c3 brought about this change.
How about making the current behavior a specification?
It has been three years since the behavior changed, and I don't see much point in prohibiting `nil` now.
https://github.com/ruby/ruby/pull/7692 updates the documentation.
--
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/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-11-30 6:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-11 0:58 [ruby-core:113180] [Ruby master Feature#19588] Allow Comparable#clamp(min, max) to accept nil as a specification kyanagi (Kouhei Yanagita) via ruby-core
2023-04-11 6:11 ` [ruby-core:113184] " sawa (Tsuyoshi Sawada) via ruby-core
2023-04-11 6:26 ` [ruby-core:113185] " sawa (Tsuyoshi Sawada) via ruby-core
2023-04-14 1:17 ` [ruby-core:113233] " mame (Yusuke Endoh) via ruby-core
2023-04-26 1:40 ` [ruby-core:113344] " kyanagi (Kouhei Yanagita) via ruby-core
2023-10-10 4:52 ` [ruby-core:114989] " kyanagi (Kouhei Yanagita) via ruby-core
2023-11-30 6:19 ` [ruby-core:115535] " mame (Yusuke Endoh) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).