https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112018-06-04T23:03:24ZRuby Issue Tracking SystemRuby master - Bug #14823: Endless Range Excluding Endhttps://redmine.ruby-lang.org/issues/14823?journal_id=723792018-06-04T23:03:24Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>This boggles my mind.</p>
<p>I thought an endless range means infinity, or "open ended". Can we reach the point<br>
before infinity, or after infinity - or "endlessity"?</p>
<p>This here also tampers with my mind:</p>
<pre><code>(1...) == (1..)
</code></pre>
<p>But in a wicked way ... adding one more '.' should make it be more than just<br>
infinity now, should it not. :)</p>
<blockquote>
<p>I think the use of ... with an endless range should be a SyntaxError.</p>
</blockquote>
<p>I agree, if only for keeping my sanity.</p> Ruby master - Bug #14823: Endless Range Excluding Endhttps://redmine.ruby-lang.org/issues/14823?journal_id=723882018-06-05T04:44:01Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>Thank you for the comment.</p>
<p>This argument is very subtle. Some (mathematical) people says that we should have <code>(1...)</code> because of two reasons:</p>
<ul>
<li>
<code>...</code> is preferably used to port Python code to Ruby because Python's <code>::</code> is literally corresponded to Ruby's <code>...</code>.</li>
<li>
<code>(1..)</code> is semantically weird because it does not include the infinity.</li>
</ul>
<p>In other aspect, I like <code>(1..)</code> for casual use because it is shorter than <code>(1...)</code>. Also, <code>ary[1..]</code> looks better than <code>ary[1...]</code>.</p>
<p>So, currently, we have both. If you have any practical issue caused by having both, let me know.</p> Ruby master - Bug #14823: Endless Range Excluding Endhttps://redmine.ruby-lang.org/issues/14823?journal_id=723902018-06-05T06:02:52Zsawa (Tsuyoshi Sawada)
<ul></ul><p>I agree with shevegen. In case one of the two is to be removed, it is <code>1..</code> that should be removed, not the other way around.</p>
<p>My understanding is that the <code>..</code> notation corresponds to the mathematical notation <code>]</code> (end of closed interval), whereas <code>...</code> corresponds to <code>)</code> (end of open interval). And in mathematics, there is such thing as</p>
<pre><code>$[1, \infty)$
</code></pre>
<p>but there is no such thing as</p>
<pre><code>$[1, \infty]$
</code></pre> Ruby master - Bug #14823: Endless Range Excluding Endhttps://redmine.ruby-lang.org/issues/14823?journal_id=723962018-06-05T06:30:32Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>mame (Yusuke Endoh) wrote:</p>
<blockquote>
<ul>
<li>
<code>(1..)</code> is semantically weird because it does not include the infinity.</li>
</ul>
</blockquote>
<p><code>(1..)</code> includes infinity. It's (1...) that doesn't include infinity.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="mi">5</span><span class="p">).</span><span class="nf">include?</span> <span class="mi">5</span> <span class="c1">#=> true</span>
<span class="p">(</span><span class="mi">1</span><span class="o">...</span><span class="mi">5</span><span class="p">).</span><span class="nf">include?</span> <span class="mi">5</span> <span class="c1">#=> false</span>
</code></pre>
<p>For enumerators, it doesn't matter whether the end of an infinite range is included or not, because we'll never reach it. But for other operations, such as <code>include?</code>, it matters.</p>
<p>Currently, we have:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="p">).</span><span class="nf">include?</span> <span class="no">Float</span><span class="o">::</span><span class="no">INFINITY</span> <span class="c1">#=> true</span>
<span class="p">(</span><span class="mi">1</span><span class="o">...</span><span class="p">).</span><span class="nf">include?</span> <span class="no">Float</span><span class="o">::</span><span class="no">INFINITY</span> <span class="c1">#=> true #### should be false?!</span>
</code></pre>
<p>mame (Yusuke Endoh) wrote:</p>
<blockquote>
<p>Also, <code>ary[1..]</code> looks better than <code>ary[1...]</code>.</p>
</blockquote>
<p>All the valid indices of the array are finite, so there's no difference here. Just having <code>ary[1..]</code> only would be fine.</p>
<p>sawa (Tsuyoshi Sawada) wrote (rewritten to use Unicode characters):</p>
<blockquote>
<p>I agree with shevegen. In case one of the two is to be removed, it is <code>1..</code> that should be removed, not the other way around.</p>
<p>My understanding is that the <code>..</code> notation corresponds to the mathematical notation <code>]</code> (end of closed interval), whereas <code>...</code> corresponds to <code>)</code> (end of open interval). And in mathematics, there is such thing as</p>
<pre><code>[1, ∞)
</code></pre>
<p>but there is no such thing as</p>
<pre><code>[1, ∞]
</code></pre>
</blockquote>
<p>It is true that this is the convention followed in Mathematics. But in Ruby, we can easily write</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="p">(</span><span class="mi">1</span><span class="o">...</span><span class="p">).</span><span class="nf">include?</span> <span class="no">Float</span><span class="o">::</span><span class="no">INFINITY</span>
</code></pre>
<p>and the answer we get currently isn't consistent with Mathematics.</p> Ruby master - Bug #14823: Endless Range Excluding Endhttps://redmine.ruby-lang.org/issues/14823?journal_id=724022018-06-05T14:31:24Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>duerst (Martin Dürst) wrote:</p>
<blockquote>
<p>mame (Yusuke Endoh) wrote:</p>
<blockquote>
<p>but there is no such thing as</p>
<pre><code>[1, ∞]
</code></pre>
</blockquote>
<p>It is true that this is the convention followed in Mathematics.</p>
</blockquote>
<p>It actually depends which mathematics we are talking about. Transfinite mathematics deal with different infinities. Check in particular the "surreal numbers".</p>
<p>Still, for Ruby, I agree that it would be best to have something simple.</p>
<p>I would accept (x..) and automagically change it to (x...).</p>
<pre><code>(42..) # => (42...)
(42..) == (42...) # => true
</code></pre>
<p>I particularly like the fact that "42..." is a nice notation for "42 and up".</p> Ruby master - Bug #14823: Endless Range Excluding Endhttps://redmine.ruby-lang.org/issues/14823?journal_id=871802020-08-25T21:24:46Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Closed</i></li></ul>