[Python-Dev] Pre-PEP: Allow Empty Subscript List Without Parentheses

Noam Raphael noamraph at gmail.com
Sat Jun 17 20:38:32 CEST 2006


2006/6/16, Josiah Carlson <jcarlson at uci.edu>:
> I'm not a mathematician, and I don't really work with arrays of any
> dimensionality, so the need for 0-D subscripting via arr[] while being
> cute, isn't compelling to my uses for Python.

Thanks for appreciating its cuteness...
> Now, I appreciate the desire to reduce code length and complexity, but
> from what I understand, the ultimate result of such a change to your
> code would be to go from:
>     arr[()]
> to:
>     arr[]
> I don't see how this can reduce lines of code in implementation or use.
> At most it is a two characters per use, and a change in documentation
> (specifying how you subscript 0-D arrays).  If you can show an example
> where actual code line count is reduced with this change, I can't
> guarantee that I would get behind this proposal in a few months (if the
> conversation starts up again), but it may make me feel less that your
> proposal is essentially about aesthetics.

I meant the extra code for writing a special class to handle scalars,
if I decide that the "x[()]" syntax is too ugly or too hard to type,
so I write a special class which will allow the syntax "x.value".

The extra parentheses might not seem to matter for code using that
library, but I intend for people to use it directly, in an interactive
way, just like you type an expression in a spreadsheet. I expect that
for such a usage, the extra parentheses will be slightly unfun.

I know that it's not such a big difference, but I'm not talking about
a big change to the language either - it affects less than 20 lines of
code (probably could be done with even less), and doesn't cause any
problems with anything.

I can imagine Guido designing the grammar, thinking, "Should I allow
an empty subscript list? No, why should anyone want such a thing?
Besides, if someone wants them, we can always add them later." - at
least, it may be how I would think if I designed a language. So now, a
use was found. Indeed, it is farely rare. But why not to allow it now?

Have a good week,

More information about the Python-Dev mailing list