unicode as valid naming symbols

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Mar 25 19:58:17 EDT 2014


On Tue, 25 Mar 2014 14:29:06 -0500, Mark H Harris wrote:

> On 3/25/14 2:24 PM, MRAB wrote:
>  > It's explained in PEP 3131.
>  >
>  > Basically, a name should to start with a letter (this has been
>  > extended to include Chinese characters, etc) or an underscore.
>  >
>  > λ is a classified as Lowercase_Letter.
>  >
>  > √ is classified as Math_Symbol.
> 
>     Thanks much!  I'll note that for improvements. Any unicode symbol
> (that is not a number) should be allowed as an identifier.


To quote a great Spaniard:

    “You keep using that word, I do not think it means what you
     think it means.”


Do you think that the ability to write this would be an improvement?

import ⌺
⌚ = ⌺.╩░
⑥ = 5*⌺.⋨⋩
❹ = ⑥ - 1
♅⚕⚛ = [⌺.✱✳**⌺.❇*❹{⠪|⌚.∣} for ⠪ in ⌺.⣚]
⌺.˘˜¨´՛՜(♅⚕⚛)


Of course, it's not even necessary to be that exotic. "Any unicode symbol 
that is not a number"... that means things like these:

x+y
spam.eggs
cheese["toast"]

would count as identifiers, which could lead to a little bit of parsing 
ambiguity... *wink*

There are languages that can allow arbitrary symbols as identifiers, like 
Lisp and Forth. You will note that they have a certain reputation for 
being, um, different, and although both went through periods of 
considerable popularity, both have faded in popularity since. While they 
have their strengths, and their defenders, nobody argues that they are 
readily accessible to the average programmer.




-- 
Steven D'Aprano
http://import-that.dreamwidth.org/



More information about the Python-list mailing list