# 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:** 1
**Showing post:** 13

<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 23, 2023, 12:15pm UTC](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591/13 "2023-03-23T12:15:57Z")

</div>

> [@tim.holy](#):
>
> You do know about `begin` and `end`?

Yes, but these only work for calculating indices within `[]`; many times you might wish to calculate indices outside, such as in the OP. Hence, the motivation for [EndyIndexes.jl](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591/7), this [suggestion](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591/8) for `$begin` and `$end`, and [EndpointRanges.jl](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591/9). (Not to mention, the motivation for the `@view` macro, @jishnub’s [OrdinalIndexing.jl](https://github.com/jishnub/OrdinalIndexing.jl), and [this thread](https://discourse.julialang.org/t/ordinal-indexing-as-a-language-feature/91970).) The suggestion to do arithmetic with `first` and `last` is just to use existing singleton objects, instead of introducing new `start_` and `end_` or `ibegin` and `iend` objects.

Additionally, because `first+x` and `last-y` could return special from-start and from-end indexing objects, they could be used for efficiently indexing strings by character (instead of by byte). For example, I’d imagine `"αβγ"[first+1:last-1]` would return `"β"` (with `getindex` making appropriate calls to `nextind` and `prevind` under the hood).

---

_[View the full topic](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591)._
