Allowing zero-dimensional subscripts

Steve Holden steve at holdenweb.com
Fri Jun 9 03:16:17 EDT 2006


spam.noam at gmail.com wrote:
> Hello,
> 
> Terry Reedy wrote:
> 
>>So I do not see any point or usefulness in saying that a tuple subcript is
>>not what it is.
> 
> 
> I know that a tuple is *constructed*. The question is, is this,
> conceptually, the feature that allows you to ommit the parentheses of a
> tuple in some cases. If we see this as the same feature, it's
> reasonable that "nothing" won't be seen as an empty tuple, just like "a
> = " doesn't mean "a = ()".
> 
> However, if we see this as a different feature, which allows
> multidimensional subscript by constructing a tuple behind the scenes,
> constructing an empty tuple for x[] seems very reasonable to me. Since
> in some cases you can't have the parentheses at all, I think that x[]
> makes sense.
> 
Hey, I have an idea, why don't we look at the language reference manual 
instead of imagining how we think it might work!

In section 3.2 we find:


"""
Tuples
The items of a tuple are arbitrary Python objects. Tuples of two or more 
items are formed by comma-separated lists of expressions. A tuple of one 
item (a `singleton') can be formed by affixing a comma to an expression 
(an expression by itself does not create a tuple, since parentheses must 
be usable for grouping of expressions). An empty tuple can be formed by 
an empty pair of parentheses.
"""

So it seems that your speculation is false. Section 2.6 specifically 
defines "[" and "]" as delimiters. Section 5.3.2 defines a subscription 
(a term I've not really grown to love, but what the heck) as

subscription ::= primary "[" expression_list "]"

and section 5.12, which defines expression_list, explicitly says

"""An expression list containing at least one comma yields a tuple.""".

So it would appear that while your change might be very convenient to 
allow you to refer to scalar values as zero-dimensional arrays, it 
doesn't really fit into Python's conceptual framework. Sorry.

One further point: if you really do conceptualize scalars as 
zero-dimensional arrays, where is the value conceptually stored?

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list