ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:90937] [Ruby trunk Bug#15518] good old Infinite range notation behavior
       [not found] <redmine.issue-15518.20190109054414@ruby-lang.org>
@ 2019-01-09  5:44 ` sakuro+ruby-lang.org
  2019-01-09  7:19 ` [ruby-core:90940] " sawadatsuyoshi
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: sakuro+ruby-lang.org @ 2019-01-09  5:44 UTC (permalink / raw)
  To: ruby-core

Issue #15518 has been reported by sakuro (Sakuro OZAWA).

----------------------------------------
Bug #15518: good old Infinite range notation behavior
https://bugs.ruby-lang.org/issues/15518

* Author: sakuro (Sakuro OZAWA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------




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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:90940] [Ruby trunk Bug#15518] good old Infinite range notation behavior
       [not found] <redmine.issue-15518.20190109054414@ruby-lang.org>
  2019-01-09  5:44 ` [ruby-core:90937] [Ruby trunk Bug#15518] good old Infinite range notation behavior sakuro+ruby-lang.org
@ 2019-01-09  7:19 ` sawadatsuyoshi
  2019-01-09  8:34 ` [ruby-core:90941] [Ruby trunk Bug#15518][Assigned] " muraken
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: sawadatsuyoshi @ 2019-01-09  7:19 UTC (permalink / raw)
  To: ruby-core

Issue #15518 has been updated by sawa (Tsuyoshi Sawada).


With finite ranges, the class of the elements in the return value seems to reflect the class of the `step` parameter as shown below (although, I am not sure why the one with rational has `1` instead of `(1/1)`. A bug, perhaps?):

```ruby
(1..10).step(1).first(5) # => [1, 2, 3, 4, 5]
(1..10).step(1.0).first(5) # => [1.0, 2.0, 3.0, 4.0, 5.0]
(1..10).step(1/1r).first(5) #=> [1, (2/1), (3/1), (4/1), (5/1)]
```

Given that, without explicit `step`, the returned numbers are integers, it should be understood that the default step for a range is the integer `1`:

```ruby
(1..10).first(5) # => [1, 2, 3, 4, 5]
```

The above claim that the class of the number is determined by the `step` parameter (and nothing else, such as the end of range) is confirmed by the fact that a range ending with `Float::INFINITY` that has default step `1` returns integers.

```ruby
(1..Float::INFINITY).first(5) #=> [1, 2, 3, 4, 5]
```

Given the argument above, I think `(1..Float::INFINITY).step(1).first(5)` should return integers as follows:

```ruby
(1..Float::INFINITY).step(1).first(5) # => [1, 2, 3, 4, 5]
```

Thus, to me, neither Ruby 2.5.3 nor Ruby 2.6.0's behavior makes sense.

----------------------------------------
Bug #15518: good old Infinite range notation behavior
https://bugs.ruby-lang.org/issues/15518#change-76140

* Author: sakuro (Sakuro OZAWA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Ruby 2.5.3's behavior

~~~
# without step, it produces integer sequence
(1..Float::INFINITY).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# with step, it produces floats instead of integers
(1..Float::INFINITY).step(1).first(10) #=> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
~~~

Ruby 2.6.0's behavior

~~~
# endless range
(1..).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# with step, all numbers are integer now
(1..).step(1).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# old idiom with Float::INFINITY
(1..Float::INFINITY).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
(1..Float::INFINITY).step(1).first(10) #=> FloatDomainError (Infinity)
~~~

Which are intended change and which are not?




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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:90941] [Ruby trunk Bug#15518][Assigned] good old Infinite range notation behavior
       [not found] <redmine.issue-15518.20190109054414@ruby-lang.org>
  2019-01-09  5:44 ` [ruby-core:90937] [Ruby trunk Bug#15518] good old Infinite range notation behavior sakuro+ruby-lang.org
  2019-01-09  7:19 ` [ruby-core:90940] " sawadatsuyoshi
@ 2019-01-09  8:34 ` muraken
  2019-01-09  9:35 ` [ruby-core:90942] [Ruby trunk Bug#15518] " muraken
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: muraken @ 2019-01-09  8:34 UTC (permalink / raw)
  To: ruby-core

Issue #15518 has been updated by mrkn (Kenta Murata).

Status changed from Open to Assigned
Assignee set to mrkn (Kenta Murata)

----------------------------------------
Bug #15518: good old Infinite range notation behavior
https://bugs.ruby-lang.org/issues/15518#change-76143

* Author: sakuro (Sakuro OZAWA)
* Status: Assigned
* Priority: Normal
* Assignee: mrkn (Kenta Murata)
* Target version: 
* ruby -v: ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Ruby 2.5.3's behavior

~~~
# without step, it produces integer sequence
(1..Float::INFINITY).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# with step, it produces floats instead of integers
(1..Float::INFINITY).step(1).first(10) #=> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
~~~

Ruby 2.6.0's behavior

~~~
# endless range
(1..).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# with step, all numbers are integer now
(1..).step(1).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# old idiom with Float::INFINITY
(1..Float::INFINITY).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
(1..Float::INFINITY).step(1).first(10) #=> FloatDomainError (Infinity)
~~~

Which are intended change and which are not?




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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:90942] [Ruby trunk Bug#15518] good old Infinite range notation behavior
       [not found] <redmine.issue-15518.20190109054414@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-01-09  8:34 ` [ruby-core:90941] [Ruby trunk Bug#15518][Assigned] " muraken
@ 2019-01-09  9:35 ` muraken
  2019-01-30  6:16 ` [ruby-core:91330] " muraken
  2019-01-30  6:20 ` [ruby-core:91331] " naruse
  5 siblings, 0 replies; 6+ messages in thread
From: muraken @ 2019-01-09  9:35 UTC (permalink / raw)
  To: ruby-core

Issue #15518 has been updated by mrkn (Kenta Murata).


At first, it isn't intentional behavior change. I should fix it, but I need to consider what is the correct behavior.

Ruby 2.5's behavior is given below:

```
$ RBENV_VERSION=2.5 irb --simple-prompt
>> (1 .. 10).first(5)
=> [1, 2, 3, 4, 5]
>> (1 .. 10.0).first(5)
=> [1, 2, 3, 4, 5]
>> (1.0 .. 10).first(5)
Traceback (most recent call last):
        4: from /Users/mrkn/.rbenv/versions/2.5/bin/irb:11:in `<main>'
        3: from (irb):3
        2: from (irb):3:in `first'
        1: from (irb):3:in `each'
TypeError (can't iterate from Float)
>> (1 .. 10r).first(5)
=> [1, 2, 3, 4, 5]
>> (1r .. 10).first(5)
Traceback (most recent call last):
        4: from /Users/mrkn/.rbenv/versions/2.5/bin/irb:11:in `<main>'
        3: from (irb):2
        2: from (irb):2:in `first'
        1: from (irb):2:in `each'
TypeError (can't iterate from Rational)
>> (1 .. 10).step(1).first(5)
=> [1, 2, 3, 4, 5]
>> (1 .. 10.0).step(1).first(5)
=> [1.0, 2.0, 3.0, 4.0, 5.0]
>> (1.0 .. 10).step(1).first(5)
=> [1.0, 2.0, 3.0, 4.0, 5.0]
>> (1 .. 10).step(1.0).first(5)
=> [1.0, 2.0, 3.0, 4.0, 5.0]
>> (1 .. 10r).step(1).first(5)
=> [1, 2, 3, 4, 5]
>> (1r .. 10).step(1).first(5)
=> [(1/1), (2/1), (3/1), (4/1), (5/1)]
>> (1 .. 10).step(1r).first(5)
=> [1, (2/1), (3/1), (4/1), (5/1)]
```

As you can see, the enumerator from Range#step is different from Range#each.
And, on Range#step, the result of the range with float components consists of Float values only while the result of the range with rational components does not.
The reason for this difference is that Range#step has the specialized implementation for the range with float components.

----------------------------------------
Bug #15518: good old Infinite range notation behavior
https://bugs.ruby-lang.org/issues/15518#change-76144

* Author: sakuro (Sakuro OZAWA)
* Status: Assigned
* Priority: Normal
* Assignee: mrkn (Kenta Murata)
* Target version: 
* ruby -v: ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Ruby 2.5.3's behavior

~~~
# without step, it produces integer sequence
(1..Float::INFINITY).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# with step, it produces floats instead of integers
(1..Float::INFINITY).step(1).first(10) #=> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
~~~

Ruby 2.6.0's behavior

~~~
# endless range
(1..).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# with step, all numbers are integer now
(1..).step(1).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# old idiom with Float::INFINITY
(1..Float::INFINITY).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
(1..Float::INFINITY).step(1).first(10) #=> FloatDomainError (Infinity)
~~~

Which are intended change and which are not?




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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:91330] [Ruby trunk Bug#15518] good old Infinite range notation behavior
       [not found] <redmine.issue-15518.20190109054414@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-01-09  9:35 ` [ruby-core:90942] [Ruby trunk Bug#15518] " muraken
@ 2019-01-30  6:16 ` muraken
  2019-01-30  6:20 ` [ruby-core:91331] " naruse
  5 siblings, 0 replies; 6+ messages in thread
From: muraken @ 2019-01-30  6:16 UTC (permalink / raw)
  To: ruby-core

Issue #15518 has been updated by mrkn (Kenta Murata).


I fixed the case for ranges whose end is Float::INFINITY.
If you want to continue to discuss for the other cases, please create the new issue.

----------------------------------------
Bug #15518: good old Infinite range notation behavior
https://bugs.ruby-lang.org/issues/15518#change-76580

* Author: sakuro (Sakuro OZAWA)
* Status: Closed
* Priority: Normal
* Assignee: mrkn (Kenta Murata)
* Target version: 
* ruby -v: ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Ruby 2.5.3's behavior

~~~
# without step, it produces integer sequence
(1..Float::INFINITY).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# with step, it produces floats instead of integers
(1..Float::INFINITY).step(1).first(10) #=> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
~~~

Ruby 2.6.0's behavior

~~~
# endless range
(1..).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# with step, all numbers are integer now
(1..).step(1).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# old idiom with Float::INFINITY
(1..Float::INFINITY).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
(1..Float::INFINITY).step(1).first(10) #=> FloatDomainError (Infinity)
~~~

Which are intended change and which are not?




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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:91331] [Ruby trunk Bug#15518] good old Infinite range notation behavior
       [not found] <redmine.issue-15518.20190109054414@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2019-01-30  6:16 ` [ruby-core:91330] " muraken
@ 2019-01-30  6:20 ` naruse
  5 siblings, 0 replies; 6+ messages in thread
From: naruse @ 2019-01-30  6:20 UTC (permalink / raw)
  To: ruby-core

Issue #15518 has been updated by naruse (Yui NARUSE).

Backport changed from 2.4: DONTNEED, 2.5: DONTNEED, 2.6: REQUIRED to 2.4: DONTNEED, 2.5: DONTNEED, 2.6: DONE

ruby_2_6 r66949 merged revision(s) 66947.

----------------------------------------
Bug #15518: good old Infinite range notation behavior
https://bugs.ruby-lang.org/issues/15518#change-76582

* Author: sakuro (Sakuro OZAWA)
* Status: Closed
* Priority: Normal
* Assignee: mrkn (Kenta Murata)
* Target version: 
* ruby -v: ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]
* Backport: 2.4: DONTNEED, 2.5: DONTNEED, 2.6: DONE
----------------------------------------
Ruby 2.5.3's behavior

~~~
# without step, it produces integer sequence
(1..Float::INFINITY).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# with step, it produces floats instead of integers
(1..Float::INFINITY).step(1).first(10) #=> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
~~~

Ruby 2.6.0's behavior

~~~
# endless range
(1..).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# with step, all numbers are integer now
(1..).step(1).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# old idiom with Float::INFINITY
(1..Float::INFINITY).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
(1..Float::INFINITY).step(1).first(10) #=> FloatDomainError (Infinity)
~~~

Which are intended change and which are not?




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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-01-30  6:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15518.20190109054414@ruby-lang.org>
2019-01-09  5:44 ` [ruby-core:90937] [Ruby trunk Bug#15518] good old Infinite range notation behavior sakuro+ruby-lang.org
2019-01-09  7:19 ` [ruby-core:90940] " sawadatsuyoshi
2019-01-09  8:34 ` [ruby-core:90941] [Ruby trunk Bug#15518][Assigned] " muraken
2019-01-09  9:35 ` [ruby-core:90942] [Ruby trunk Bug#15518] " muraken
2019-01-30  6:16 ` [ruby-core:91330] " muraken
2019-01-30  6:20 ` [ruby-core:91331] " naruse

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).