# Confusing parsing behavior

**URL:** https://discourse.julialang.org/t/confusing-parsing-behavior/60615
**Category:** New to Julia
**Tags:** question
**Created:** [May 6, 2021, 2:56am UTC](https://discourse.julialang.org/t/confusing-parsing-behavior/60615 "2021-05-06T02:56:01Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![ChunXi\_Zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chunxi_zhang/32/22556_2.png) [@ChunXi\_Zhang](https://discourse.julialang.org/u/ChunXi_Zhang)
#### Post date: [May 6, 2021, 2:56am UTC](https://discourse.julialang.org/t/confusing-parsing-behavior/60615/1 "2021-05-06T02:56:02Z")

</div>

When I try to concatenate 2 ranges, I accidentally write:

```julia
[1 : 2; 6 :9]

```

and there is an Error:

```julia
ArgumentError: number of columns of each array must match (got (1, 2))

```

while these all works:

```julia
[1:2; 6:9]
[1 : 2; 6 : 9]
[1 : 2; 6: 9]
6 :9

```

(Pay attention to these spaces)

Can anyone explain why is it like that? Is it intended or a bug?

---

<div class="post-metadata">

### Author: ![learned\_fool](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/learned_fool/32/21934_2.png) [@learned\_fool](https://discourse.julialang.org/u/learned_fool)
#### Post date: [May 6, 2021, 3:47am UTC](https://discourse.julialang.org/t/confusing-parsing-behavior/60615/2 "2021-05-06T03:47:08Z")

</div>

In the example you’ve shown, I think `:9` is treated as a separate symbol, instead as a part of the unit range. On `julia1.6.1`, comparing `[6 :9]` and `[1 : 2]` gives me:

```julia
julia> [6 :9]
1×2 Matrix{Int64}:
 6 9
julia> [1 : 2]
1-element Vector{UnitRange{Int64}}:
 1:2

```

Whereas julia is able to correctly parse expressions like `6:9`, `6 : 9`, `6: 9` into unit ranges.

Since the number of elements differ, you get a dimension mismatch.

---

<div class="post-metadata">

### Author: ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)
#### Post date: [May 6, 2021, 4:17am UTC](https://discourse.julialang.org/t/confusing-parsing-behavior/60615/3 "2021-05-06T04:17:06Z")

</div>

Indeed, you can see the documentation about symbol doing:

```julia
help?> Symbol
search: Symbol

  Symbol

  The type of object used to represent identifiers in parsed julia code (ASTs). Also often used as a name or label to identify an entity (e.g. as a dictionary key). Symbols can
  be entered using the : quote operator:

  julia> :name
  :name

  julia> typeof(:name)
  Symbol

  julia> x = 42
  42

  julia> eval(:x)
  42

  Symbols can also be constructed from strings or other values by calling the constructor Symbol(x...).

  Symbols are immutable and should be compared using ===. The implementation re-uses the same object for all Symbols with the same name, so comparison tends to be efficient (it
  can just compare pointers).

  Unlike strings, Symbols are "atomic" or "scalar" entities that do not support iteration over characters.

```

---

<div class="post-metadata">

### Author: ![ChunXi\_Zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chunxi_zhang/32/22556_2.png) [@ChunXi\_Zhang](https://discourse.julialang.org/u/ChunXi_Zhang)
#### Post date: [May 6, 2021, 4:20am UTC](https://discourse.julialang.org/t/confusing-parsing-behavior/60615/4 "2021-05-06T04:20:44Z")

</div>

But actually, `typeof(:9)` returns Int64, which is not a symbol.

---

<div class="post-metadata">

### Author: ![ChunXi\_Zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chunxi_zhang/32/22556_2.png) [@ChunXi\_Zhang](https://discourse.julialang.org/u/ChunXi_Zhang)
#### Post date: [May 6, 2021, 4:40am UTC](https://discourse.julialang.org/t/confusing-parsing-behavior/60615/5 "2021-05-06T04:40:20Z")

</div>

I thought `:9` is interpreted as a symbol and get promoted, then everything make sense.  
But actually I found `:9` is exactly `9` as Int, why is that?

```julia
:9 === 9 # true

```

---

<div class="post-metadata">

### Author: ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)
#### Post date: [May 6, 2021, 5:32am UTC](https://discourse.julialang.org/t/confusing-parsing-behavior/60615/6 "2021-05-06T05:32:35Z")

</div>

A `Symbol` can’t be written like that because they are primarily for representing code as data (julia code can be represented as data in other julia code), and I assume `:9` isn’t valid because variable names can’t start with a number. I’m not sure why it evaluates as `9`!

But this means your array evaluates as:

```julia
[1:2; 6 9]

```

Which does have 1 and 2 columns, explaining your error.

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [May 6, 2021, 8:01am UTC](https://discourse.julialang.org/t/confusing-parsing-behavior/60615/7 "2021-05-06T08:01:50Z")

</div>

The important thing to note is that `:()` doesn’t create symbols, it quotes its argument (like `quote`, but not as a block). If you want to create a symbol, use `Symbol`:

```julia
julia> Symbol(2)
Symbol("2")

```

---

<div class="post-metadata">

### Author: ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)
#### Post date: [May 6, 2021, 8:26am UTC](https://discourse.julialang.org/t/confusing-parsing-behavior/60615/8 "2021-05-06T08:26:00Z")

</div>

```julia
julia> :(2) |> typeof
Int64

julia> quote 2 end |> typeof
Expr

```

it doesn’t seem to be quoting here?

---

<div class="post-metadata">

### Author: ![ChunXi\_Zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chunxi_zhang/32/22556_2.png) [@ChunXi\_Zhang](https://discourse.julialang.org/u/ChunXi_Zhang)
#### Post date: [May 6, 2021, 8:28am UTC](https://discourse.julialang.org/t/confusing-parsing-behavior/60615/9 "2021-05-06T08:28:21Z")

</div>

I don’t want to create a number Symbol, but it seems that julia is interpreting `:9` as `9` unexpectedly. Which is the source of this confusing behavior.  
But why? I don’t think symbol could explain that…

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [May 6, 2021, 8:29am UTC](https://discourse.julialang.org/t/confusing-parsing-behavior/60615/10 "2021-05-06T08:29:39Z")

</div>

`:` is one of the most overloaded and whitespace-sensitive constructs in Julia. So yes, it’s confusing, but shouldn’t pose much of a problem if you’re careful with your whitespace.

---

<div class="post-metadata">

### Author: ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)
#### Post date: [May 6, 2021, 8:54am UTC](https://discourse.julialang.org/t/confusing-parsing-behavior/60615/11 "2021-05-06T08:54:39Z")

</div>

`quote x end` not only quotes `x` but also wraps `x` in a `begin ... end` block (a `block` expression).
