Can I use \parallel or \perp in variables' names

Some unicode symbols cannot be used in variables’ names.
For example,

julia> C∥ = 1
ERROR: syntax: unexpected "="
Stacktrace:
 [1] top-level scope at none:1

julia> C⟂ = 2
ERROR: syntax: unexpected "="
Stacktrace:
 [1] top-level scope at none:1

However, this works

julia> ∥ = 1
1

Combinations of normal symbols and \perp or \parallel are not allowed.
Is there a reason for this behavior? If so, is there a workaround so that I can use them in names?

For perpendicular you can use \bot and for parallel I use z in the absence of something closer to parallel lines that aren’t parsed as or.

Good. \bot is a good replacement for \perp.
I’m still curious why some symbols are not allowed.
I’ve tried several like ⥣ or ⦷ and they are like \perp and \parallel.
Allowing them in the variables’ names should help the readability.

Those unicode symbols are operators and are parsed specially. You can see the full list of operators here:
https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm

You can make a variable named C∥ with var"C∥" but you have to use the var thing everywhere then so thats a pretty ugly workaround

To give an example of the intended use of these symbols, you could define as an operator that checks if two vectors are colinear:

julia> using LinearAlgebra

julia> a∥b = norm(a)*norm(b) ≈ abs(a⋅b);

julia> [1,2,3] ∥ [2,4,6]
true

julia> [1,2,3] ∥ [2,4,7]
false

1 Like

@WschW Thanks for the explanation.

@FPGro Thanks, it is indeed not a good solution… C_para might be better than var"C∥".

@sijo Thanks, the example is neat.

Since those symbols are hardcoded in the parser, it seems there is no way to workaround this.
The best alternative I can find is probably C\_=, which gives a subscript equal sign.

You might also like these ones:

julia> 'ǁ'
'ǁ': Unicode U+01C1 (category Lo: Letter, other)

julia> '║'
'║': Unicode U+2551 (category So: Symbol, other)

julia> '┴'
'┴': Unicode U+2534 (category So: Symbol, other)
1 Like

These are amazing! Thanks.

1 Like