From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.1 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id A34EC1F803 for ; Wed, 9 Jan 2019 09:35:10 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id EC09C121E76; Wed, 9 Jan 2019 18:35:05 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 2C955121C37 for ; Wed, 9 Jan 2019 18:35:02 +0900 (JST) Received: by filter0076p3iad2.sendgrid.net with SMTP id filter0076p3iad2-8414-5C35C044-35 2019-01-09 09:35:00.728857212 +0000 UTC m=+118068.629029096 Received: from herokuapp.com (ec2-54-82-77-37.compute-1.amazonaws.com [54.82.77.37]) by ismtpd0065p1mdw1.sendgrid.net (SG) with ESMTP id y05mARb3Qc2imV0D5dtjGQ for ; Wed, 09 Jan 2019 09:35:00.492 +0000 (UTC) Date: Wed, 09 Jan 2019 09:35:01 +0000 (UTC) From: muraken@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 66373 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15518 X-Redmine-Issue-Author: sakuro X-Redmine-Issue-Assignee: mrkn X-Redmine-Sender: mrkn X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS6F+f5hd+eOWQ4//TgOUCxxern0kddFl6+ijk ARUy6aR95e0qjmiBbKQSjzOYDuFvVPQB/o1rm8kaisVJtqgyVxjb4bLEb/dMAnDwZ1ZyGKy7QM/LtH xwa+uxUR879fCMSZfk/miqzhZk0WUSTNLwinGVNIZSbF30o2Yo8hVHclEg== X-ML-Name: ruby-core X-Mail-Count: 90942 Subject: [ruby-core:90942] [Ruby trunk Bug#15518] good old Infinite range notation behavior X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "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 `
' 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 `
' 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/