# ParseError in comprehension when whitespace removed

**URL:** https://discourse.julialang.org/t/parseerror-in-comprehension-when-whitespace-removed/132780
**Category:** General Usage
**Created:** [September 30, 2025, 8:39am UTC](https://discourse.julialang.org/t/parseerror-in-comprehension-when-whitespace-removed/132780 "2025-09-30T08:39:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Tigerbyte](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@Tigerbyte](https://discourse.julialang.org/u/Tigerbyte)
#### Post date: [September 30, 2025, 8:39am UTC](https://discourse.julialang.org/t/parseerror-in-comprehension-when-whitespace-removed/132780/1 "2025-09-30T08:39:43Z")

</div>

```julia-auto
julia> [2*x + 6 for x in 1:3]
3-element Vector{Int64}:
  8
 10
 12

julia> "above as expected, now take away the blank before the 6"
"above as expected, now take away the blank before the 6"

julia> [2*x +6 for x in 1:3]
ERROR: ParseError:
# Error @ REPL[10]:1:22
[2*x +6 for x in 1:3]
# ╙ ── unexpected `]`
Stacktrace:
 [1] top-level scope
   @ none:1

```

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [September 30, 2025, 12:31pm UTC](https://discourse.julialang.org/t/parseerror-in-comprehension-when-whitespace-removed/132780/2 "2025-09-30T12:31:37Z")

</div>

This is essentially the same as the whitespace effects you asked about in [Whitespace effects in x+1](https://discourse.julialang.org/t/whitespace-effects-in-x-1/132783) … Julia is sensitive to whitespace in some contexts, especially with the `+` operator (which can be either prefix or infix) and especially inside `[...]` brackets (which can be either comprensions or array literals, with special whitespace-based syntax for matrix literals).

It’s safer to give an error in cases where the parsing is ambiguous. That being said, the error message here could probably be clearer.

PS. See [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530) … I’ve fixed it for you above.

PPS. I’ve edited your post title to make the subject of this thread clearer.

---

<div class="post-metadata">

### Author: ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)
#### Post date: [September 30, 2025, 12:57pm UTC](https://discourse.julialang.org/t/parseerror-in-comprehension-when-whitespace-removed/132780/3 "2025-09-30T12:57:08Z")

</div>

And, as in [Whitespace effects in x+1 - #2 by goerz](https://discourse.julialang.org/t/whitespace-effects-in-x-1/132783/2) : Whenever an element of a Vector or Array is some complex expression, put parentheses around that expression. Always err on the side of more parentheses!

---

<div class="post-metadata">

### Author: ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)
#### Post date: [September 30, 2025, 1:02pm UTC](https://discourse.julialang.org/t/parseerror-in-comprehension-when-whitespace-removed/132780/4 "2025-09-30T13:02:53Z")

</div>

As a side note, there is an ongoing discussion here: [Add `strict` mechanism for opting into stricter subsets of the language · Issue #54903 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/54903) about optionally disallowing various undesirable language features. One of the topics has been spacing which disagrees with the precedence rules, like: `a * b+c * d` and `a ^ b*c`.
