# Why can't I use any Unicode character in field name?

**URL:** <https://discourse.julialang.org/t/why-cant-i-use-any-unicode-character-in-field-name/81715>\
**Category:** General Usage\
**Created:** [May 26, 2022, 12:40pm UTC](https://discourse.julialang.org/t/why-cant-i-use-any-unicode-character-in-field-name/81715 "2022-05-26T12:40:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 26, 2022, 12:40pm UTC](https://discourse.julialang.org/t/why-cant-i-use-any-unicode-character-in-field-name/81715/1 "2022-05-26T12:40:16Z")

</div>

Hello!

I am just trying this:

```julia
struct Vec{Ti <: Number, Tj <: Number, Tk <: Number}
        ₁::Ti
        ₂::Tj
        ₃::Tk
    end

```

And it does not work for these unicode characters, but works for something like “\bbN”.

I am trying to see if I can make a syntax like:

```julia
a = Vec(1,1,1)

# Return first element
a₁

```

Is it possible?

Kind regards

---

<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:** [May 26, 2022, 12:51pm UTC](https://discourse.julialang.org/t/why-cant-i-use-any-unicode-character-in-field-name/81715/2 "2022-05-26T12:51:19Z")

</div>

See [Allowed Variable names](https://docs.julialang.org/en/v1/manual/variables/#man-allowed-variable-names) in the manual: identifiers cannot start with a number (including numeric subscripts).

Every programming language has some restrictions on the characters allowed in identifiers, and Julia is more permissive than most. (Python doesn’t allow numeric subscripts at all, e.g. `x₃` is not a valid Python 3 identifier. Similarly for most other languages, thanks to a [fairly restrictive recommendation](https://unicode.org/reports/tr31/) from the Unicode consortium.)

See [this issue](https://github.com/JuliaLang/julia/pull/20278) for discussion on allowing identifiers to start with numeric subscripts/superscripts.

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 26, 2022, 12:54pm UTC](https://discourse.julialang.org/t/why-cant-i-use-any-unicode-character-in-field-name/81715/3 "2022-05-26T12:54:17Z")

</div>

Thanks!

I hope it becomes permissible one day. I would love to write as close to math as possible, makes it much easier for me atleast.

I hope the suggestion with sub- and superscripts gets through sometime 🙂

Kind regards

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [May 26, 2022, 12:57pm UTC](https://discourse.julialang.org/t/why-cant-i-use-any-unicode-character-in-field-name/81715/4 "2022-05-26T12:57:21Z")

</div>

You’d still have to write `v.₁` rather than `v₁`. `v[1]` is already widely considered to be the programming equivalent of subscripting with 1.

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 26, 2022, 12:59pm UTC](https://discourse.julialang.org/t/why-cant-i-use-any-unicode-character-in-field-name/81715/5 "2022-05-26T12:59:19Z")

</div>

I do not disagree at all, I had hoped there was a smart way to avoid the “.” as well, that I was not aware of yet 🙂

I suppose I just like when it looks more as `a₁` than a[1].

So this is one of the points I liked about Julia, thinking that I could write exactly how I would have wanted, but unfortunately not in this case. I guess some restrictions have to be in place.

Thanks for your comment!

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [May 26, 2022, 1:01pm UTC](https://discourse.julialang.org/t/why-cant-i-use-any-unicode-character-in-field-name/81715/6 "2022-05-26T13:01:01Z")

</div>

`a₁` is already a valid variable name, which isn’t going to change—it’s useful and changing it would be a breaking change. So that will never be possible as a syntax for `a[1]`.

---

<div class="post-metadata">

**Author:** ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)\
**Post date:** [May 26, 2022, 2:12pm UTC](https://discourse.julialang.org/t/why-cant-i-use-any-unicode-character-in-field-name/81715/7 "2022-05-26T14:12:45Z")

</div>

> [@Ahmed\_Salih](#):
>
> I am trying to see if I can make a syntax like:
> 
> ```julia
> a = Vec(1,1,1)
> 
> # Return first element
> a₁
> 
> ```

You could always manually assign `a₁` to `a.₁` (similarly for the other entries), or create a macro to automate it. E.g., `@fancy_macro a = Vec(1, 1, 1) # Also defines a₁, etc.`

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 26, 2022, 2:17pm UTC](https://discourse.julialang.org/t/why-cant-i-use-any-unicode-character-in-field-name/81715/8 "2022-05-26T14:17:29Z")

</div>

Do you happen to know how?

---

<div class="post-metadata">

**Author:** ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)\
**Post date:** [May 26, 2022, 2:34pm UTC](https://discourse.julialang.org/t/why-cant-i-use-any-unicode-character-in-field-name/81715/9 "2022-05-26T14:34:41Z")

</div>

Here’s a basic implementation that has no error checking (note that I changed the fields of the `Vec` struct to `i`, `j`, and `k`):

```julia
julia> macro define_fields(ex)
           name = ex.args[1]
           esc(quote
               $ex
               $(Symbol(name, "₁")) = $name.i
               $(Symbol(name, "₂")) = $name.j
               $(Symbol(name, "₃")) = $name.k
               $name
           end)
       end
@define_fields (macro with 1 method)

julia> @define_fields a = Vec(1, 2, 3)
Vec{Int64, Int64, Int64}(1, 2, 3)

julia> a₁, a₂, a₃
(1, 2, 3)

julia> @define_fields long_name = Vec(10, 20, 30)
Vec{Int64, Int64, Int64}(10, 20, 30)

julia> long_name₁, long_name₂, long_name₃
(10, 20, 30)

```

You could probably come up with a better name for the macro.
