https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112022-05-18T16:39:29ZRuby Issue Tracking SystemRuby master - Feature #18749: Strangeness of endless inclusive rangeshttps://bugs.ruby-lang.org/issues/18749?journal_id=976502022-05-18T16:39:29Zjanosch-x (Janosch Müller)
<ul></ul><p>Maybe a simple, non-breaking solution would be to make endless Ranges exclude the end regardless of how they are written?</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="mi">1</span><span class="o">..</span><span class="kp">nil</span> <span class="c1"># => 1...</span>
<span class="mi">1</span><span class="o">...</span><span class="kp">nil</span> <span class="c1"># => 1...</span>
<span class="c1"># as a result:</span>
<span class="mi">1</span><span class="o">..</span><span class="kp">nil</span> <span class="o">==</span> <span class="mi">1</span><span class="o">...</span><span class="kp">nil</span> <span class="c1"># => true</span>
<span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="kp">nil</span><span class="p">).</span><span class="nf">cover?</span><span class="p">(</span><span class="mi">1</span><span class="o">...</span><span class="kp">nil</span><span class="p">)</span> <span class="c1"># => true</span>
<span class="p">(</span><span class="mi">1</span><span class="o">...</span><span class="kp">nil</span><span class="p">).</span><span class="nf">cover?</span><span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="kp">nil</span><span class="p">)</span> <span class="c1"># => true</span>
</code></pre> Ruby master - Feature #18749: Strangeness of endless inclusive rangeshttps://bugs.ruby-lang.org/issues/18749?journal_id=976712022-05-19T08:44:15Zsawa (Tsuyoshi Sawada)
<ul></ul><p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/12619">@janosch-x (Janosch Müller)</a> (Janosch Müller) That seems to be a good idea. That is a possible compromise. Thank you for the idea.</p> Ruby master - Feature #18749: Strangeness of endless inclusive rangeshttps://bugs.ruby-lang.org/issues/18749?journal_id=976842022-05-20T13:31:05Zsawa (Tsuyoshi Sawada)
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/97684/diff?detail_id=62533">diff</a>)</li></ul> Ruby master - Feature #18749: Strangeness of endless inclusive rangeshttps://bugs.ruby-lang.org/issues/18749?journal_id=979762022-06-14T07:07:53Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>We were aware of this issue, and we agreed with the current behavior. This thread in Twitter discusses the issue: <a href="https://twitter.com/mrkn/status/987509913365594112" class="external">https://twitter.com/mrkn/status/987509913365594112</a></p>
<p>Here is a simple English translation:</p>
<ul>
<li>ko1: Under <code>ary = [1, 2, 3]</code>, what <code>ary[1..]</code> and <code>ary[1...]</code> return respectively?</li>
<li>mame: <code>ary[1..]</code> should return <code>[2, 3]</code>. I don't know <code>ary[1...]</code>
</li>
<li>matz: <code>ary[1...]</code> should also return <code>[2, 3]</code>
</li>
<li>shugo: How is <code>1...</code> useful?</li>
<li>mrkn: <code>1...</code> is mathematically correct</li>
<li>shugo: Okay, but we want to write <code>1..</code> in practical, so having both looks good</li>
<li>mrkn: I will write <code>1...</code> in practical, but <code>1..</code> is acceptable as the same meaning as <code>1...</code>
</li>
<li>shugo: What should <code>(1..).exclude_end?</code> return?</li>
<li>mrkn: I want it to be false formally because <code>1..</code> is something unnatural</li>
<li>shugo: I agree with you</li>
<li>mame: Let keep the current behavior as is until there is a use case</li>
</ul>
<p>So I close this issue. Let me know if you have a practical use case to change the behavior.</p>
<p>BTW, I have a new question about exclusive endless range: <code>(0...).include?(Float::INFINITY)</code> returns true currently, but should it return false? (IMO, the current behavior is good enough.)</p> Ruby master - Feature #18749: Strangeness of endless inclusive rangeshttps://bugs.ruby-lang.org/issues/18749?journal_id=979882022-06-14T09:45:45Zsawa (Tsuyoshi Sawada)
<ul></ul><p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/18">@mame (Yusuke Endoh)</a> san, thanks for letting me know about the discussion.</p>
<p>It looks to me that the discussion you quoted was directed toward letting <code>1..</code> be an alias of <code>1...</code>, just like <a href="https://bugs.ruby-lang.org/issues/18749#note-1" class="external">https://bugs.ruby-lang.org/issues/18749#note-1</a> suggests, all the way up to shugo's comment "I agree with you". And then, it suddenly ended with your comment "Let [us] keep the current behavior as is until there is a use case," which is a different approach.</p>
<p>However, since you claim so, I do not oppose your decision to close this issue.</p>
<p>Regarding <code>(0...).include?(Float::INFINITY)</code>, from a mathematical standpoint, ∞ (counterpart to <code>Float::INFINITY</code>) is not a real number whereas [0, ∞) (counterpart to <code>0...</code>) is a subset of real numbers, so I think it should return <code>false</code>.</p> Ruby master - Feature #18749: Strangeness of endless inclusive rangeshttps://bugs.ruby-lang.org/issues/18749?journal_id=980742022-06-17T09:25:37Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>sawa (Tsuyoshi Sawada) wrote in <a href="#note-5">#note-5</a>:</p>
<blockquote>
<p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/18">@mame (Yusuke Endoh)</a> san, thanks for letting me know about the discussion.</p>
<p>It looks to me that the discussion you quoted was directed toward letting <code>1..</code> be an alias of <code>1...</code>, just like <a href="https://bugs.ruby-lang.org/issues/18749#note-1" class="external">https://bugs.ruby-lang.org/issues/18749#note-1</a> suggests, all the way up to shugo's comment "I agree with you". And then, it suddenly ended with your comment "Let [us] keep the current behavior as is until there is a use case," which is a different approach.</p>
</blockquote>
<p>It was a typo in his tweet. <a class="user active user-mention" href="https://bugs.ruby-lang.org/users/482">@mrkn (Kenta Murata)</a> meant "I want it to be false formally". I confirmed him, and I updated my previous comment.</p>