# Using end variable in ranges passed to functions other than getindex?

**URL:** <https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591>\
**Category:** General Usage\
**Tags:** indexing\
**Created:** [December 7, 2017, 2:04am UTC](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591 "2017-12-07T02:04:44Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![lmtzx9h4qqnt](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@lmtzx9h4qqnt](https://discourse.julialang.org/u/lmtzx9h4qqnt)\
**Post date:** [March 28, 2023, 6:44pm UTC](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591/21 "2023-03-28T18:44:38Z")

</div>

> [@uniment](#):
>
> I’m not sure why unitrange `a:b` clamps to `a:a-1` for `b` much less than `a`; maybe that can be changed?

This has bothered me as well on several occasions, because it makes it impossible to do anything interesting with the additional information (e. g. giving an extended meaning to it, such as discussed here with indexing). For what it’s worth, Python ranges keep this information:

```python
>>> range(1, -10)
range(1, -10)
>>> list(range(1, -10))
[]

```

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [March 28, 2023, 10:10pm UTC](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591/22 "2023-03-28T22:10:39Z")

</div>

I vaguely recall someone a couple of years ago messing with changing `a:b` to _not_ normalize to `a:max(a-1,b)`. Ultimately they abandoned it. I recall that `length` needed to be redefined from `b-a+1`, presumably to something like `max(b-a+1,0)`, but surely there must have been something more sinister than that to have sunk it.

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [March 29, 2023, 7:55am UTC](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591/23 "2023-03-29T07:55:08Z")

</div>

Do you remember what their motivation for trying was?

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [March 29, 2023, 1:55pm UTC](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591/24 "2023-03-29T13:55:47Z")

</div>

Nope. They wanted to be able to use the end value for something more interesting when the range was empty, but my memory is much too poor to remember more. I did a quick search through old PRs but didn’t find it. A more thorough search through issues and PRs might turn something up unless it was just a Discourse thread.

[Previous page](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591.md?page=1)
