# Difficulties with unicode arrows in function names

**URL:** <https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736>\
**Category:** New to Julia\
**Tags:** function\
**Created:** [March 22, 2021, 4:59pm UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736 "2021-03-22T16:59:10Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![markmbaum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/markmbaum/32/32745_2.png) [@markmbaum](https://discourse.julialang.org/u/markmbaum)\
**Post date:** [March 22, 2021, 4:59pm UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/1 "2021-03-22T16:59:10Z")

</div>

I think it would look nice to have up and down arrows in some function names that compute upward and downward propagating properties, but I’m getting errors when I try to use them. In my REPL, when I try

```julia
test↑(x, y) = x + y

```

I just get

```julia
↑ (generic function with 1 method)

```

as if the arrow were the whole function name.

When I try to use arrows in module functions, I get errors like

```julia
LoadError: "expected \"end\" in definition of function \"schwarzschild\""

```

or

```julia
LoadError: "invalid character \"⇈\" near column 23"

```

Is this a system problem? Any way to fix it?

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [March 22, 2021, 5:03pm UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/2 "2021-03-22T17:03:42Z")

</div>

`↑` is parsed as a binary operator, so you actually defined a function of variables `test` and `(x, y)` (using destructuring) that returns `x+y` 🙂

```julia
julia> test↑(x, y) = println("$test, $x, $y")
↑ (generic function with 2 methods)

julia> 2↑(3,4)
2, 3, 4

```

The error you see could be the parser being confused when you don’t use `↑` as a binary operator…

---

<div class="post-metadata">

**Author:** ![markmbaum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/markmbaum/32/32745_2.png) [@markmbaum](https://discourse.julialang.org/u/markmbaum)\
**Post date:** [March 22, 2021, 5:05pm UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/3 "2021-03-22T17:05:44Z")

</div>

That would explain the issues with ↑, but what about ⇈ or ⇑? They both cause errors. Is it just the same problem? Why the `invalid character` error?

---

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [March 22, 2021, 5:39pm UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/4 "2021-03-22T17:39:29Z")

</div>

Aren’t those all listed as Julia operators in

> <https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm>

example:

```julia
julia> abc⟰def = 1
⟰ (generic function with 1 method)

julia> 123 ⟰ 456
1

```

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [March 22, 2021, 6:41pm UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/5 "2021-03-22T18:41:07Z")

</div>

> [@markmbaum](#):
>
> Why the `invalid character` error?

The parser file linked by @pbayer shows which Unicode characters are recognized as operators. This includes `↑` but not `⇈` and `⇑`. Note that these characters have different Unicode categories:

```julia
julia> collect("↑⇈⇑")
3-element Array{Char,1}:
 '↑': Unicode U+2191 (category Sm: Symbol, math)
 '⇈': Unicode U+21C8 (category So: Symbol, other)
 '⇑': Unicode U+21D1 (category So: Symbol, other)

```

The [documentation](https://docs.julialang.org/en/v1/manual/variables/#Allowed-Variable-Names) says:

> Variable names must begin with a letter (A-Z or a-z), underscore, or a subset of Unicode code points greater than 00A0; in particular, [Unicode character categories](http://www.fileformat.info/info/unicode/category/index.htm) Lu/Ll/Lt/Lm/Lo/Nl (letters), Sc/So (currency and other symbols), and a few other letter-like characters (e.g. a subset of the Sm math symbols) are allowed. Subsequent characters may also include ! and digits (0-9 and other characters in categories Nd/No), as well as other Unicode code points: diacritics and other modifying marks (categories Mn/Mc/Me/Sk), some punctuation connectors (category Pc), primes, and a few other characters. […] Most of the Unicode infix operators (in category Sm), such as `⊕` , are parsed as infix operators and are available for user-defined methods (e.g. you can use `const ⊗ = kron` to define `⊗` as an infix Kronecker product).

So `↑` being parsed as a binary operator is expected

On the other hand it is suprising that `⇈` and `⇑` are not allowed as identifiers, since they have category So. Maybe file an issue?

---

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [March 22, 2021, 6:59pm UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/6 "2021-03-22T18:59:17Z")

</div>

> [@sijo](#):
>
> This includes `↑` but not `⇈` and `⇑` .

yep, you are right:

```julia
julia> abc⇈def = 2
ERROR: syntax: invalid character "⇈" near column 4
Stacktrace:
 [1] top-level scope
   @ none:1

```

Thanks!

---

<div class="post-metadata">

**Author:** ![brianguenter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brianguenter/32/29519_2.png) [@brianguenter](https://discourse.julialang.org/u/brianguenter)\
**Post date:** [June 28, 2021, 6:24am UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/7 "2021-06-28T06:24:53Z")

</div>

I want to use ⇑, ⇘, etc., as variable names. It looks like this should be allowed by the variable naming rules but I get an error:

```julia
julia> ⇘ = 1
ERROR: syntax: invalid character "⇘" near column 1

```

It doesn’t look like ⇑ or ⇘ should be parsed as an operator; neither of them occurs in [JuliaLang/julia/blob/master/src/julia-parser.scm](https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm) .  
They are both in the category So which is supposed to be a valid character for a variable name:

```julia
julia> collect("⇑,⇘")
1-element Vector{Char}:
 '⇘': Unicode U+21D8 (category So: Symbol, other)

```

Is this a bug? Or am I misreading the variable name rules?

---

<div class="post-metadata">

**Author:** ![brianguenter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brianguenter/32/29519_2.png) [@brianguenter](https://discourse.julialang.org/u/brianguenter)\
**Post date:** [June 28, 2021, 6:25am UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/8 "2021-06-28T06:25:58Z")

</div>

I want to use ⇑, ⇘, etc., as variable names. It looks like this should be allowed by the variable naming rules but I get an error:

```julia
julia> ⇘ = 1
ERROR: syntax: invalid character "⇘" near column 1

```

It doesn’t look like ⇑ or ⇘ should be parsed as an operator; neither of them occurs in [JuliaLang/julia/blob/master/src/julia-parser.scm](https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm) .  
They are both in the category So which is supposed to be a valid character for a variable name:

```julia
julia> collect("⇑,⇘")
1-element Vector{Char}:
 '⇘': Unicode U+21D8 (category So: Symbol, other)

```

Is this a bug? Or am I misreading the variable name rules?

---

<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:** [June 28, 2021, 6:28am UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/9 "2021-06-28T06:28:57Z")

</div>

Looks like a bug to me.

```julia
julia> '⇘'
'⇘': Unicode U+21D8 (category So: Symbol, other)

```

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [June 28, 2021, 7:58am UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/10 "2021-06-28T07:58:15Z")

</div>

Try some of the arrows in the range 0x2b00:0x2bFF - and, if you’re feeling adventurous, 0x1f800:0x1f8FF.

 ![Screenshot 2021-06-28 at 08.53.49](https://global.discourse-cdn.com/julialang/original/3X/b/1/b1468c5b024107afee135eb079c8907f4162a878.png)

I don’t know where “the rules” are described (other than in the source code), but you can use `Meta.isidentifier()` to check whether a string is a valid identifier.

---

<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:** [June 28, 2021, 8:04am UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/11 "2021-06-28T08:04:06Z")

</div>

> [@cormullion](#):
>
> I don’t know where “the rules” are described (other than in the source code)

There’s a bit in the docs

> [@sijo](#):
>
> The [documentation](https://docs.julialang.org/en/v1/manual/variables/#Allowed-Variable-Names) says:
> 
> > Variable names must begin with a letter (A-Z or a-z), underscore, or a subset of Unicode code points greater than 00A0; in particular, [Unicode character categories](http://www.fileformat.info/info/unicode/category/index.htm) Lu/Ll/Lt/Lm/Lo/Nl (letters), Sc/So (currency and other symbols)

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [June 28, 2021, 8:07am UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/12 "2021-06-28T08:07:00Z")

</div>

“subset” is the operative word, though…?

---

<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:** [June 28, 2021, 8:14am UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/13 "2021-06-28T08:14:44Z")

</div>

My reading of that is that it’s a subset of Unicode code points greater than 00A0, and in particular the subset comprises _all_ of the code points with “Unicode character categories Lu/Ll/Lt/Lm/Lo/Nl (letters), Sc/So (currency and other symbols)” and so on.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [June 28, 2021, 8:18am UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/14 "2021-06-28T08:18:42Z")

</div>

I don’t understand much of [the source](https://github.com/stevengj/julia/blob/18eccd3e698f570f959d3bcbfc90af28d001cbe2/src/flisp/julia_extensions.c#L59), but it looks like a white-list, rather than _all_.

---

<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:** [June 28, 2021, 8:27am UTC](https://discourse.julialang.org/t/difficulties-with-unicode-arrows-in-function-names/57736/15 "2021-06-28T08:27:42Z")

</div>

Then I suppose either the source or the docs should be changed to match the other. Dunno which one ¯\_(ツ)_/¯
