# What is the current (and future) status of \`begin\` keyword in indexing?

**URL:** <https://discourse.julialang.org/t/what-is-the-current-and-future-status-of-begin-keyword-in-indexing/13145>\
**Category:** General Usage\
**Created:** [August 10, 2018, 6:14am UTC](https://discourse.julialang.org/t/what-is-the-current-and-future-status-of-begin-keyword-in-indexing/13145 "2018-08-10T06:14:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![geoalchimista](https://avatars.discourse-cdn.com/v4/letter/g/f05b48/32.png) [@geoalchimista](https://discourse.julialang.org/u/geoalchimista)\
**Post date:** [August 10, 2018, 6:14am UTC](https://discourse.julialang.org/t/what-is-the-current-and-future-status-of-begin-keyword-in-indexing/13145/1 "2018-08-10T06:14:17Z")

</div>

I’ve started moving my projects to Julia 1.0. I find that the `begin` keyword in array index has been removed. I get an error trying to use it

```julia
julia> x = [1,2,3,4]
4-element Array{Int64,1}:
 1
 2
 3
 4
x[begin:end]
┌ Warning: Deprecated syntax `"begin" inside indexing expression` at REPL[19]:1.
└ @ REPL[19]:1
ERROR: syntax: extra token "]" after end of expression

julia> x[begin]
┌ Warning: Deprecated syntax `"begin" inside indexing expression` at REPL[21]:1.
└ @ REPL[21]:1
ERROR: syntax: unexpected "]"

```

The release note of 0.7 says that

> `begin` is disallowed inside indexing expressions, in order to enable the syntax `a[begin]` (for selecting the first element) in the future (#23354).

I’m a bit confused. Does this mean that in a future version, `a[begin]` will be allowed but `a[begin:end-2]` will be illegal?

Thanks!

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [August 10, 2018, 7:30am UTC](https://discourse.julialang.org/t/what-is-the-current-and-future-status-of-begin-keyword-in-indexing/13145/2 "2018-08-10T07:30:09Z")

</div>

In Julia 0.6 it was valid to do

```julia
julia> a = rand(5)
5-element Array{Float64,1}:
 0.0143824 
 0.359066  
 0.568123  
 0.00120256
 0.547529  

julia> a[begin
             x = rand(1:2)
             y = rand(1:3)
             x + y
         end]
0.5475289624323161

```

This has been deprecated so that it will be possible in the future to allow syntax like `a[begin]`, `a[begin:end]`, `a[begin:end-2]` and so on to work with `begin` as an indexing counterpart to `end`, rather than starting a block inside the indexing.

---

<div class="post-metadata">

**Author:** ![dawbarton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dawbarton/32/215461_2.png) [@dawbarton](https://discourse.julialang.org/u/dawbarton)\
**Post date:** [August 10, 2018, 8:43am UTC](https://discourse.julialang.org/t/what-is-the-current-and-future-status-of-begin-keyword-in-indexing/13145/3 "2018-08-10T08:43:08Z")

</div>

If you do want the previous behaviour for any reason, you can still use brackets to achieve it. The example becomes

```julia
a[(x = rand(1:2); y = rand(1:3); x + y)]

```

---

<div class="post-metadata">

**Author:** ![geoalchimista](https://avatars.discourse-cdn.com/v4/letter/g/f05b48/32.png) [@geoalchimista](https://discourse.julialang.org/u/geoalchimista)\
**Post date:** [August 10, 2018, 5:08pm UTC](https://discourse.julialang.org/t/what-is-the-current-and-future-status-of-begin-keyword-in-indexing/13145/4 "2018-08-10T17:08:21Z")

</div>

Thank you! I didn’t know that a `begin`-block was allowed in the index in 0.6.x. Felt a bit hackish though and I probably wouldn’t feel comfortable to use it anyway. Reserving the `begin` keyword to mean the first index seems a great decision to me.

---

<div class="post-metadata">

**Author:** ![geoalchimista](https://avatars.discourse-cdn.com/v4/letter/g/f05b48/32.png) [@geoalchimista](https://discourse.julialang.org/u/geoalchimista)\
**Post date:** [August 10, 2018, 5:14pm UTC](https://discourse.julialang.org/t/what-is-the-current-and-future-status-of-begin-keyword-in-indexing/13145/5 "2018-08-10T17:14:06Z")

</div>

Thanks for the tip! This looks neater than the `begin ... end` block to me. If I have more complicated indexing expressions I would probably use a list comprehension.
