<div dir="ltr">+1 for the example you used.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jan 20, 2014 at 7:09 AM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Mon, Jan 20, 2014 at 11:12 PM, spir <<a href="mailto:denis.spir@gmail.com">denis.spir@gmail.com</a>> wrote:<br>


> For instance, closed intervals are more intuitive or natural, obviously (but<br>
> for some reason I don't know). If you ask someone to count from 1 to 9, you<br>
> will probably be surprised to hear him/her start from 2 or stop after 8. If<br>
> you are asked to choose a letter between c and g, you will probably be<br>
> surprised to hear that 'c' or 'g' is no good choice.<br>
<br>
</div>I'm not so sure about that. The half-open interval makes as much sense<br>
as the fully closed - all you have to do is interpret the indices as<br>
being *between* elements. Take, for example, Scripture verses. (Quotes<br>
taken from THE HOLY BIBLE, NEW INTERNATIONAL VERSION®, NIV® Copyright<br>
© 1973, 1978, 1984, 2011 by Biblica, Inc.® Used by permission. All<br>
rights reserved worldwide. Copyright notice included for license<br>
compliance. Note that I'm using bracketed numbers to indicate the<br>
beginnings of verses - in a printed Bible, these would normally be in<br>
superscript.)<br>
<br>
John 14:<br>
[31] To the Jews who had believed him, Jesus said, “If you hold to my<br>
teaching, you are really my disciples. [32] Then you will know the<br>
truth, and the truth will set you free.” [33]<br>
<br>
This passage is normally referred to as "John 14:31-32", but as you<br>
see, the verse marker [32] is in the middle of the quote. Using a<br>
half-open interval, this would start at "John 14:31" and end at "John<br>
14:33". Half-open means: "Begin at the beginning, go on till you come<br>
to the end, then stop", as the King of Hearts instructed the White<br>
Rabbit.<br>
<br>
It's easy to indicate the beginning of a chapter: your start reference<br>
is verse 1. Here's the beginning of the account of the creation of the<br>
world:<br>
<br>
[1] In the beginning God created the heavens and the earth. [2] Now<br>
the earth was formless and empty, darkness was over the surface of the<br>
deep, and the Spirit of God was hovering over the waters. [3] And God<br>
said, “Let there be light,” and there was light. [4] God saw that the<br>
light was good, and he separated the light from the darkness. [5] God<br>
called the light “day,” and the darkness he called “night.” And there<br>
was evening, and there was morning—the first day. [6]<br>
<br>
Common parlance: Genesis 1:1-5. Half-open: Genesis 1:1-6. Conclusion:<br>
Tie. No argument to be made for either side. But what if you're<br>
looking at the *end* of a chapter? Here are a few verses from later on<br>
in Genesis 1:<br>
<br>
[29] Then God said, “I give you every seed-bearing plant on the face<br>
of the whole earth and every tree that has fruit with seed in it. They<br>
will be yours for food. [30] And to all the beasts of the earth and<br>
all the birds of the air and all the creatures that move on the<br>
ground—everything that has the breath of life in it—I give every green<br>
plant for food.” And it was so. [31] God saw all that he had made, and<br>
it was very good. And there was evening, and there was morning—the<br>
sixth day.<br>
<br>
Common parlance: Genesis 1:29-31. Half-open: Genesis 1:29-2:1. It's<br>
much more obvious by the latter that this passage extends exactly to<br>
the end of the chapter.<br>
<br>
Obviously it's way WAY too late to change the way Bible references are<br>
written, any more than Melway could renumber their maps all of a<br>
sudden. Massive case of lock-in and backward-incompatibility with<br>
existing code. But I put it to you that the half-open would make at<br>
least as much sense as the closed, in any situation where there are<br>
boundaries with contents between them.<br>
<br>
Note, by the way, that I'm not looking at anything involving backward<br>
scanning or wider strides, both of which Python's slice notation<br>
supports. Neither of those is inherently real-world intuitive, so the<br>
exact semantics can be defined as whatever makes sense in code. (And<br>
there was some discussion a little while ago about exactly that.) I'm<br>
just looking at the very simple and common case of referencing a<br>
subset of consecutive elements from a much larger whole.<br>
<br>
The closed interval makes more sense when the indices somehow *are*<br>
the values being retrieved. When you count from 1 to 9, you expect<br>
nine numbers: 1, 2, ..., 8, 9. When you list odd numbers from 1 to 9,<br>
you expect 1, 3, 5, 7, 9. But what if you're looking at a container<br>
train and numbering the twenty-foot-equivalent-units (TEU) that it<br>
has? A 40-foot container requires 2 TEU, a 60-foot container requires<br>
3 TEU. A "reefer" (refridgerated container) might require an extra<br>
slot, or at least it might be a 56-footer and consume 3 TEU. One wagon<br>
might, if you're lucky, carry 5 TEU; numbering them 1 through 5 would<br>
be obvious, but numbering the boundaries between them as 0 through 5<br>
is better at handling the multiple TEU containers. (Even more so when<br>
you look at double-stacked containers. An over-height 40-foot<br>
container could consume 2 TEU horizontally and 2 TEU vertically, and<br>
be put in slots (0,0)-(2,2). This is, in fact, exactly how a GTK2<br>
Table layout works.) Both types of intervals have their places.<br>
<br>
ChrisA<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Ryan<div><span style="color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:18px"><font>When your hammer is C++, everything begins to look like a thumb.</font></span><br>

</div></div>
</div>