# Syntax error in an array expression

**URL:** https://discourse.julialang.org/t/syntax-error-in-an-array-expression/22607
**Category:** General Usage
**Tags:** question, error, syntax
**Created:** [April 1, 2019, 5:06pm UTC](https://discourse.julialang.org/t/syntax-error-in-an-array-expression/22607 "2019-04-01T17:06:52Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![vvjn](https://avatars.discourse-cdn.com/v4/letter/v/5f9b8f/32.png) [@vvjn](https://discourse.julialang.org/u/vvjn)
#### Post date: [April 1, 2019, 5:06pm UTC](https://discourse.julialang.org/t/syntax-error-in-an-array-expression/22607/1 "2019-04-01T17:06:52Z")

</div>

I ran the following code `A = rand(2,3); A[1, 2 +1]` and I got this error `ERROR: syntax: missing separator in array expression`. Same error with `i=2; A[1, i +1]`, which is how I came across this. Of course, `A[1,2+1]` works without issues. I was just wondering if this is supposed to happen. Thanks.

---

<div class="post-metadata">

### Author: ![JonasIsensee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasisensee/32/4704_2.png) [@JonasIsensee](https://discourse.julialang.org/u/JonasIsensee)
#### Post date: [April 1, 2019, 5:25pm UTC](https://discourse.julialang.org/t/syntax-error-in-an-array-expression/22607/2 "2019-04-01T17:25:08Z")

</div>

Hi @vvjn,  
I believe this is intended. Allowing it might be dangerous because  
you might just have forgotten a `,` instead of wanting to add something.  
In that case this could be a _silent_ error.

```julia
julia> [1, 2 +2]
ERROR: syntax: missing separator in array expression

julia> [1, 2+2]
2-element Array{Int64,1}:
 1
 4

julia> [1, 2, +2]
3-element Array{Int64,1}:
 1
 2
 2

```

---

<div class="post-metadata">

### Author: ![vvjn](https://avatars.discourse-cdn.com/v4/letter/v/5f9b8f/32.png) [@vvjn](https://discourse.julialang.org/u/vvjn)
#### Post date: [April 1, 2019, 8:07pm UTC](https://discourse.julialang.org/t/syntax-error-in-an-array-expression/22607/3 "2019-04-01T20:07:35Z")

</div>

Okay, sounds good. I thought it was odd since `2 +1` works outside the array syntax.

---

<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: [April 2, 2019, 6:00am UTC](https://discourse.julialang.org/t/syntax-error-in-an-array-expression/22607/4 "2019-04-02T06:00:04Z")

</div>

Yes, unfortunately array syntax (`[...]`) is one of the few places where whitespace has special syntactic significance.

---

<div class="post-metadata">

### Author: ![Ju\_ska](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@Ju\_ska](https://discourse.julialang.org/u/Ju_ska)
#### Post date: [November 17, 2025, 3:29pm UTC](https://discourse.julialang.org/t/syntax-error-in-an-array-expression/22607/5 "2025-11-17T15:29:02Z")

</div>

Oh that should be more advertised.  
Is there any link around which shows the good practices ?

I’ve just encountered this error with a code which works well when launched manually, but not launched from within a shell script.

---

<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: [November 18, 2025, 8:59am UTC](https://discourse.julialang.org/t/syntax-error-in-an-array-expression/22607/6 "2025-11-18T08:59:23Z")

</div>

This is a very old topic and it makes little sense to revive it, the syntax changed in the meantime. If you have a specific question, please open a new topic, with details. The array literals are now explained in the [manual](https://docs.julialang.org/en/v1/manual/arrays/#man-array-concatenation) with plenty of examples.

---

<div class="post-metadata">

### Author: ![Ju\_ska](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@Ju\_ska](https://discourse.julialang.org/u/Ju_ska)
#### Post date: [November 18, 2025, 10:19am UTC](https://discourse.julialang.org/t/syntax-error-in-an-array-expression/22607/7 "2025-11-18T10:19:22Z")

</div>

I found the answer to my problem in this thread so I guess it’s alive and kicking 😉.
