Syntax: Escape hatch for unicode haters

You can do something now with a string macro, no parser changes needed:

macro uvar_str(s::AbstractString)
   sym = Meta.parse(unescape_string(s))
   sym isa Symbol || throw(ArgumentError("expecting a single symbol"))
   return esc(sym)
end

Which lets you do e.g.:

julia> uvar"\ub5" = 3
3

julia> µ
3

julia> uvar"\u2208"('b', "foobar") # 'b' ∈ "foobar"
true

If you want to be a friendlier you could support REPL tab completions too (by calling the REPLCompletions module), or implement even more LaTeX syntax.

It would be an easy thing to put into a module, e.g. UnicodeHaters.jl or ASCIIJulia.jl for people who want this kind of thing.

PS. I think it’s generally good style for APIs to provide ASCII synonyms, but there are exceptions, e.g. the Gridap.jl package uses Unicode so extensively in its API that it’s hard to imagine it without it.

7 Likes