# Why some operator symbols aren't allowed?

**URL:** <https://discourse.julialang.org/t/why-some-operator-symbols-arent-allowed/38104>\
**Category:** General Usage\
**Created:** [April 23, 2020, 8:40pm UTC](https://discourse.julialang.org/t/why-some-operator-symbols-arent-allowed/38104 "2020-04-23T20:40:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronneesley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronneesley/32/11072_2.png) [@Ronneesley](https://discourse.julialang.org/u/Ronneesley)\
**Post date:** [April 23, 2020, 8:40pm UTC](https://discourse.julialang.org/t/why-some-operator-symbols-arent-allowed/38104/1 "2020-04-23T20:40:36Z")

</div>

Hello,

Why some symbols aren’t allowed to create new operators?

```julia
julia> →(a, b) = a + b
julia> 1 → 2
3

julia> ∠(a, b) = a + b
julia> 1 ∠ 2
ERROR: syntax: extra token "∠" after end of expression
Stacktrace:
 [1] top-level scope at REPL[3]:0

```

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [April 23, 2020, 8:46pm UTC](https://discourse.julialang.org/t/why-some-operator-symbols-arent-allowed/38104/2 "2020-04-23T20:46:51Z")

</div>

The Julia parser only recognizes [this](https://github.com/JuliaLang/julia/blob/eaa2c58aeb12f27c1d8c116ab111773a4fc4495f/src/julia-parser.scm#L13-L31) predefined set of symbols as infix operators.

---

<div class="post-metadata">

**Author:** ![Ronneesley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronneesley/32/11072_2.png) [@Ronneesley](https://discourse.julialang.org/u/Ronneesley)\
**Post date:** [April 23, 2020, 8:49pm UTC](https://discourse.julialang.org/t/why-some-operator-symbols-arent-allowed/38104/3 "2020-04-23T20:49:43Z")

</div>

To exclude some reasons:

```julia
julia> →
ERROR: UndefVarError: → not defined

julia> ∠
ERROR: UndefVarError: ∠ not defined

```

They aren’t in use yet.

```julia
julia> '→'
'→': Unicode U+2192 (category Sm: Symbol, math)

julia> '∠'
'∠': Unicode U+2220 (category Sm: Symbol, math)

```

And, both are Unicode.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [April 23, 2020, 10:10pm UTC](https://discourse.julialang.org/t/why-some-operator-symbols-arent-allowed/38104/4 "2020-04-23T22:10:19Z")

</div>

It’s a difficult balance because making an operator infix is not free. Allowing a symbol to be used infix can often make it more awkward to use regularly.

For example, a question appeared on Slack yesterday about why you can’t declare a struct whose name is `*`:

```julia
julia> struct * <: Real
           n::Int
       end 
ERROR: syntax: "*" is not a unary operator
Stacktrace:
 [1] top-level scope at none:0
 [2] eval(::Module, ::Any) at ./boot.jl:331
 [3] eval_user_input(::Any, ::REPL.REPLBackend) at /home/mason/julia/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
 [4] run_backend(::REPL.REPLBackend) at /home/mason/.julia/packages/Revise/0meWR/src/Revise.jl:1075
 [5] top-level scope at none:0

```

The answer is that this is being parsed funny due to `*` being infix. Instead, you need to wrap `*` in parens to make it parse correctly:

```julia
julia> struct (*) <: Real
           n::Int
       end

julia> *(1)
*(1)

```

Because of stuff like this, we keep a small list of allowed infix operators and only add new ones if someone can offer a compelling reason why they or anyone else would want that particular symbol.

---

<div class="post-metadata">

**Author:** ![Ronneesley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronneesley/32/11072_2.png) [@Ronneesley](https://discourse.julialang.org/u/Ronneesley)\
**Post date:** [April 23, 2020, 11:16pm UTC](https://discourse.julialang.org/t/why-some-operator-symbols-arent-allowed/38104/5 "2020-04-23T23:16:17Z")

</div>

Hello @Mason,

Thanks for these concerns.

I proposed the operator at [Polar coordinate representation · Issue #35576 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/35576).
