unicode as valid naming symbols

Ian Kelly ian.g.kelly at gmail.com
Wed Mar 26 17:37:19 CET 2014


On Wed, Mar 26, 2014 at 2:52 AM, Antoon Pardon
<antoon.pardon at rece.vub.ac.be> wrote:
> On 26-03-14 03:56, MRAB wrote:
>> Or as a root operator, e.g. 3 √ x (the cube root of x).
>>
> Personally I would think such an operator is too limited to include in a programming language.
> This kind of notation is only used with a constant to indicate what kind of root is taken and
> only with positive integers. Something like the equivallent of the following I have never seen.
>
>   t = 2.5
>   x = 8.2
>   y = t √ x

An example is taking the geometric mean of an arbitrary number of values:

    product = functools.reduce(operator.mul, values, 1)
    n = len(values)
    geometric_mean = n √ product

I might argue though for the inverted syntax (product √ n) to more
closely parallel division.


> Of course we don't have to follow mathematical convention with python. However allowing any
> unicode symbol as an identifier doesn't prohibit from using √ as an operator. We do have
> "in" and "is" as operators now, even if they would otherwise be acceptable identifiers.
> So I wonder, would you consider to introduce log as an operator. 2 log x seems an interesting
> operation for a programmer.

If it's going to become an operator, then it has to be a keyword.
Changing a token that is currently allowed to be an identifier into a
keyword is generally avoided as much as possible, because it breaks
backward compatibility.  "in" and "is" have both been keywords for a
very long time, perhaps since the initial release of Python.



More information about the Python-list mailing list