# Space-sensitive parsing confusion

**URL:** https://discourse.julialang.org/t/space-sensitive-parsing-confusion/964
**Category:** New to Julia
**Created:** [December 15, 2016, 4:51am UTC](https://discourse.julialang.org/t/space-sensitive-parsing-confusion/964 "2016-12-15T04:51:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![achugb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/achugb/32/8080_2.png) [@achugb](https://discourse.julialang.org/u/achugb)
#### Post date: [December 15, 2016, 4:51am UTC](https://discourse.julialang.org/t/space-sensitive-parsing-confusion/964/1 "2016-12-15T04:51:18Z")

</div>

This is confusing.

```julia
julia> 1 + 2
3

julia> 1 +2
3

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

julia> [1 +2]
1×2 Array{Int64,2}:
 1 2

```

Is there a place in the manual where I can find this behavior described?

---

<div class="post-metadata">

### Author: ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)
#### Post date: [December 15, 2016, 5:44am UTC](https://discourse.julialang.org/t/space-sensitive-parsing-confusion/964/2 "2016-12-15T05:44:17Z")

</div>

Several operators are parsed as [unary](https://en.wikipedia.org/wiki/Unary_operation) when immediately adjacent to a number or variable (the operand), but binary otherwise. I don’t think there is any explicit description like the examples you give, but the behavior follows from the operator definitions: [http://docs.julialang.org/en/release-0.5/manual/mathematical-operations/](http://docs.julialang.org/en/release-0.5/manual/mathematical-operations/)

An extra line or two in the manual might be useful since this has certainly come up before.

(The other operators with dual behavior are `+ - $ & ~`. See [here](https://github.com/JuliaLang/julia/blob/0408aa206330fd2bd149efb58c0772740a0580aa/src/julia-parser.scm#L76))

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [December 15, 2016, 6:11am UTC](https://discourse.julialang.org/t/space-sensitive-parsing-confusion/964/3 "2016-12-15T06:11:08Z")

</div>

Julia understands that you want to perform a binary operation when the infix operator (a) is not separated from the operands, or (b) is separated from both operands by a space, or (c) is separated from the second operand by a space:

```
  julia> 1+2, 1 + 2, 1+ 2, [1+2], [1 + 2], [1+ 2]
  3, 3, 3, [3], [3], [3]

```

When the first operand is separated from the operator by a space but the second operand is not separated from the operator by a space, then what happens inside brackets is different than before. Inside of brackets, the space character acts as a synonym for the column separator character, the semi-colon.

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

julia> [1;2;3]
1×3 Array{Int64,2}:
1 2 3
julia> [1 2 3]
1×3 Array{Int64,2}:
1 2 3

```

---

<div class="post-metadata">

### Author: ![achugb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/achugb/32/8080_2.png) [@achugb](https://discourse.julialang.org/u/achugb)
#### Post date: [December 15, 2016, 6:11am UTC](https://discourse.julialang.org/t/space-sensitive-parsing-confusion/964/4 "2016-12-15T06:11:28Z")

</div>

Thanks! That make sense.
