Re: Allowing zero-dimensional subscripts

2006-06-10 Thread George Sakkis
[EMAIL PROTECTED] wrote: > George Sakkis wrote: > > [EMAIL PROTECTED] wrote: > > > > > However, I'm designing another library for > > > managing multi-dimensional arrays of data. Its purpose is similiar to > > > that of a spreadsheet - analyze data and preserve the relations between > > > a source

Re: Allowing zero-dimensional subscripts

2006-06-10 Thread spam . noam
George Sakkis wrote: > [EMAIL PROTECTED] wrote: > > > However, I'm designing another library for > > managing multi-dimensional arrays of data. Its purpose is similiar to > > that of a spreadsheet - analyze data and preserve the relations between > > a source of a calculation and its destination. >

Re: Allowing zero-dimensional subscripts

2006-06-10 Thread Tim N. van der Leeuw
greg wrote: > Carl Banks wrote: > > > Think of it this way: an array with n-dimensions of length 3 would have > > 3**n total entries. How many entries would a 0-dimensional array have? > > 3**0 == 1. > > Er, hang on a minute. Along which dimension of this > 0-dimensional array does it have a len

Re: Allowing zero-dimensional subscripts

2006-06-10 Thread greg
Carl Banks wrote: > Think of it this way: an array with n-dimensions of length 3 would have > 3**n total entries. How many entries would a 0-dimensional array have? > 3**0 == 1. Er, hang on a minute. Along which dimension of this 0-dimensional array does it have a length of 3? :-) -- Greg --

Re: Allowing zero-dimensional subscripts

2006-06-10 Thread Fredrik Lundh
Carl Banks wrote: > How would you index a 2-D array? With a 2-tuple. > How would you index a 1-D array? With a 1-tuple. > How would you index a 0-D array? ... array dimensions don't exist at the Python level. you're confusing behaviour that a custom class may provide with Python's view of th

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread George Sakkis
[EMAIL PROTECTED] wrote: > However, I'm designing another library for > managing multi-dimensional arrays of data. Its purpose is similiar to > that of a spreadsheet - analyze data and preserve the relations between > a source of a calculation and its destination. Sounds interesting. Will it be r

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread Carl Banks
Fredrik Lundh wrote: > noam's proposal is to make this work: > > >>> x[] > () > > (but should it really result in an empty tuple? wouldn't None be a bit > more Pythonic?) How would you index a 2-D array? With a 2-tuple. How would you index a 1-D array? With a 1-tuple. How would you index a 0-D

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread Carl Banks
Steve Holden wrote: > Carl Banks wrote: > > Steve Holden wrote: > > > >>Hey, I have an idea, why don't we look at the language reference manual > >>instead of imagining how we think it might work! > > > > > > I don't know. Sounds risky. > > > > > > > >>In section 3.2 we find: > >> > >> > >>""" >

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread spam . noam
Hello, Following Fredrik's suggestion, I wrote a pre-PEP. It's available on the wiki, at http://wiki.python.org/moin/EmptySubscriptListPEP and I also copied it to this message. Have a good day, Noam PEP: XXX Title: Allow Empty Subscript List Without Parentheses Version: $Revision$ Last-Modified

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread Antoon Pardon
Op 2006-06-08, [EMAIL PROTECTED] schreef <[EMAIL PROTECTED]>: > Hello, > > Terry Reedy wrote: >> > In a few more words: Currently, an object can be subscripted by a few >> > elements, separated by commas. It is evaluated as if the object was >> > subscripted by a tuple containing those elements. >>

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread spam . noam
Hello, Fredrik Lundh wrote: > (but should it really result in an empty tuple? wouldn't None be a bit > more Pythonic?) I don't think it would. First of all, x[()] already has the desired meaning in numpy. But I think it's the right thing - if you think of what's inside the brackets as a list of

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread spam . noam
Hello, Sybren Stuvel wrote: > I think it's ugly to begin with. In math, one would write simply 'x' > to denote an unsubscribed (ubsubscripted?) 'x'. And another point, why > would one call __getitem__ without an item to call? I think that in this case, mathematical notation is different from pyth

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread Fredrik Lundh
Sybren Stuvel wrote: > Just curious: how would you initialize 'x' in such a case? If I simply > say 'x = []' and then try to index it with x[1, 2], I get "TypeError: > list indices must be integers". that's up to the x implementation to decide, of course: >>> class MyContainer: ... def __ge

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread Steve Holden
Carl Banks wrote: > Steve Holden wrote: > >>Hey, I have an idea, why don't we look at the language reference manual >>instead of imagining how we think it might work! > > > I don't know. Sounds risky. > > > >>In section 3.2 we find: >> >> >>""" >>Tuples >>The items of a tuple are arbitrary P

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread Carl Banks
Steve Holden wrote: > Hey, I have an idea, why don't we look at the language reference manual > instead of imagining how we think it might work! I don't know. Sounds risky. > In section 3.2 we find: > > > """ > Tuples > The items of a tuple are arbitrary Python objects. Tuples of two or more >

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The question is, is this, > conceptually, the feature that allows you to ommit the parentheses of a > tuple in some cases. To repeat: tuples are defined by commas. There are no 'parentheses of a tuple', except for empty tuples, to b

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Well, what do you think about this? -0 from me, but it's definitely a PEP-able proposal. suggestion: turn your post into a pre-PEP and post it somewhere, post the patch to the patch tracker, and post a brief heads-up to python-dev, and see what happens. (you probabl

Re: Allowing zero-dimensional subscripts

2006-06-09 Thread Steve Holden
[EMAIL PROTECTED] 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

Re: Allowing zero-dimensional subscripts

2006-06-08 Thread spam . noam
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 t

Re: Allowing zero-dimensional subscripts

2006-06-08 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Terry Reedy wrote: >> > In a few more words: Currently, an object can be subscripted by a few >> > elements, separated by commas. It is evaluated as if the object was >> > subscripted by a tuple containing those elements. >> >> It is n

Re: Allowing zero-dimensional subscripts

2006-06-08 Thread spam . noam
Hello, Terry Reedy wrote: > > In a few more words: Currently, an object can be subscripted by a few > > elements, separated by commas. It is evaluated as if the object was > > subscripted by a tuple containing those elements. > > It is not 'as if'. 'a,b' *is* a tuple and the object *is* subcript

Re: Allowing zero-dimensional subscripts

2006-06-08 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello, > > I discovered that I needed a small change to the Python grammar. I > would like to hear what you think about it. > > In two lines: > Currently, the expression "x[]" is a syntax error. > I suggest that it will be evaluated li

Allowing zero-dimensional subscripts

2006-06-08 Thread spam . noam
Hello, I discovered that I needed a small change to the Python grammar. I would like to hear what you think about it. In two lines: Currently, the expression "x[]" is a syntax error. I suggest that it will be evaluated like "x[()]", just as "x[a, b]" is evaluated like "x[(a, b)]" right now. In a