# Julia's history: array indexing

**URL:** <https://discourse.julialang.org/t/julias-history-array-indexing/14390>\
**Category:** Internals & Design\
**Created:** [September 1, 2018, 12:14am UTC](https://discourse.julialang.org/t/julias-history-array-indexing/14390 "2018-09-01T00:14:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![00vareladavid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/00vareladavid/32/23521_2.png) [@00vareladavid](https://discourse.julialang.org/u/00vareladavid)\
**Post date:** [September 1, 2018, 12:14am UTC](https://discourse.julialang.org/t/julias-history-array-indexing/14390/1 "2018-09-01T00:14:59Z")

</div>

I just noticed that `xs[length(xs)+1+n:end]` returns an empty vector instead of throwing a bounds error. I think this is brilliant!

When was this behavior introduced? I don’t think I’ve seen this behavior in other languages. I’m curious if there was a discussion around this? Maybe a PR?

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [September 1, 2018, 12:22am UTC](https://discourse.julialang.org/t/julias-history-array-indexing/14390/2 "2018-09-01T00:22:45Z")

</div>

AFAIK, it’s always been that way. `length(xs)+1+n:end` is just syntax for `length(xs)+1+n:lastindex(xs)`, and ranges that end before they start are empty, so the getindex function returns immediately.

---

<div class="post-metadata">

**Author:** ![00vareladavid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/00vareladavid/32/23521_2.png) [@00vareladavid](https://discourse.julialang.org/u/00vareladavid)\
**Post date:** [September 1, 2018, 12:42am UTC](https://discourse.julialang.org/t/julias-history-array-indexing/14390/3 "2018-09-01T00:42:10Z")

</div>

Ah, that makes a lot of sense, thanks for explaining. You all rock!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 1, 2018, 5:21am UTC](https://discourse.julialang.org/t/julias-history-array-indexing/14390/4 "2018-09-01T05:21:35Z")

</div>

The earliest manual I can find online is [v0.3.12](https://docs.julialang.org/en/v0.3.12/manual/arrays/#indexing), and it already talks about empty ranges like `n:n-1`.

I also remember liking this choice very much, after R’s

```nohighlight
> 3:2
[1] 3 2

```

which demands that one special-cases these in many loops.
