Invalid unicode variable

From what I’ve read, Julia supports unicode literals in symbol names. However, when trying to name a Type “∃Formula”, an error occurs:

struct ∃Formula
  formula::String
end

ERROR: LoadError: syntax: invalid character “∃”

Other unicode characters, such as π, seem to work.

Not all Unicode codepoints are allowed in variable names.

In particular, (U+2203) is in Unicode category Sm (Symbol, math). Some of the characters in Sm are parsed as identifiers, and some of them are parsed as binary and/or unary operators. When it wasn’t clear whether a character should be an identifier or an operator, we chose not to allow it at all for the time being.

is not currently allowed because it wasn’t clear whether it should be an identifier character or some kind of (unary?) operator. If there is a compelling case for one choice or the other, we can always add it to the list of allowed characters in the future without breaking any code.

π, in contrast, is in Unicode category Ll (Letter, lowercase). All category-Ll characters are allowed in identifiers — no case-by-case decision is required.

Note that most languages, even those like Python 3 that allow Unicode identifiers, don’t allow any category-Sm characters in identifiers. That’s probably because the official Unicode recommendation for identifier characters is extremely conservative; in Julia we went beyond this recommendation to allow a much wider range of characters in order to support common mathematical notations.

5 Likes

Interesting, thanks for the detailed response!

Afaik, ∃ is only used in predicate logic (for which I’m currently building a module.) For now, I’ll use a normal E instead of ∃.

Yes, the mathematical meaning is clear but how to best make use of the symbol in Julia code is not. Allowing it in identifiers would prevent it’s use as an operator, for example.