Re: [Python-Dev] comprehension abbreviation (was: Adding any() and all())

2005-03-15 Thread Eric Nieuwland
Martin v. Löwis wrote:
That's not the full syntax. The full syntax is
[ test for exprlist in testlist list-iter-opt ]
where
test can be an arbitrary expression: and, or, lambda, +, -, ...
exprlist can be a list of expression, except for boolean and
relational expressions (but I think this is further constrained
semantically)
testlist list a list of tests
list-iter-opt is optional, and can be another for or if block
Aren't these names a bit mixed up w.r.t. what's in that position? As 
far as I know
test is not a test but a function as it produces any value not just 
True/False
exprlst is a list of names, not arbitrary expressions
testlist is anything which will produce an iterator

Or so I've understood so far.
So a more complex example is
   [ lambda a: a[x]+y*z for x,y in A for z in B if x  z]
I'm schocked ;-)
--eric
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] comprehension abbreviation (was: Adding any() and all())

2005-03-15 Thread Brett C.
Eric Nieuwland wrote:
Martin v. Löwis wrote:
That's not the full syntax. The full syntax is
[ test for exprlist in testlist list-iter-opt ]
where
test can be an arbitrary expression: and, or, lambda, +, -, ...
exprlist can be a list of expression, except for boolean and
relational expressions (but I think this is further constrained
semantically)
testlist list a list of tests
list-iter-opt is optional, and can be another for or if block

Aren't these names a bit mixed up w.r.t. what's in that position?
The names come directly from the grammar file (Grammar/Grammar) and thus have 
multiple uses.  Basically ignore the actual names and just consider them 
placeholders.

-Brett
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] comprehension abbreviation

2005-03-15 Thread Martin v. Löwis
Eric Nieuwland wrote:
[ test for exprlist in testlist list-iter-opt ]
Aren't these names a bit mixed up w.r.t. what's in that position? 
It comes more-or-less straight out of Grammar/Grammar, so: no,
I don't think so.
As far as I know
test is not a test but a function as it produces any value not just 
True/False
To quote more of Grammar/Grammar, it is
test: and_test ('or' and_test)* | lambdef
and_test: not_test ('and' not_test)*
not_test: 'not' not_test | comparison
comparison: expr (comp_op expr)*
comp_op: ''|''|'=='|'='|'='|''|'!='|'in'|'not' 'in'|'is'|'is' 'not'
expr: xor_expr ('|' xor_expr)*
...
power: atom trailer* ['**' factor]
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
So a function call is a power is a factor is a term is an arith_expr
is a shift_expr is an and_expr is a xor_expr is an expr is a comparison
is a not_test is an and_test is a test.
exprlst is a list of names, not arbitrary expressions
No, it's more than that. I can also be
  a, (b, c, (d, e))
But as I said: there are further (semantical) constraints what
kind of expression you can have there.
Regards,
Martin
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] comprehension abbreviation (was: Adding any() and all())

2005-03-14 Thread Eric Nieuwland
Gareth McCaughan wrote:
I'd like it, and my reason isn't just to save typing.
There are two reasons.
  1 Some bit of my brain is convinced that [x in stuff if condition]
is the Right Syntax and keeps making me type it even though
I know it doesn't work.
  2 Seeing [x for x in stuff if condition] triggers my internal
duplicated-stuff alarm, and it's distracting, in the same sort
of way as it's distracting in C or C++ seeing
The full syntax is:
	[ f(x) for x in seq if pred(x) ]
being allowed to write 'x' instead of 'identity(x)' is already a 
shortcut, just as dropping the conditional part.

Remember we're doing set theory stuff here. IMHO we should follow its 
notation conventions as much as we can.

--eric
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] comprehension abbreviation (was: Adding any() and all())

2005-03-14 Thread Gareth McCaughan
On Monday 2005-03-14 12:42, Eric Nieuwland wrote:
 Gareth McCaughan wrote:
 
  I'd like it, and my reason isn't just to save typing.
  There are two reasons.
 
1 Some bit of my brain is convinced that [x in stuff if condition]
  is the Right Syntax and keeps making me type it even though
  I know it doesn't work.
 
2 Seeing [x for x in stuff if condition] triggers my internal
  duplicated-stuff alarm, and it's distracting, in the same sort
  of way as it's distracting in C or C++ seeing
 
 The full syntax is:
   [ f(x) for x in seq if pred(x) ]
 being allowed to write 'x' instead of 'identity(x)' is already a 
 shortcut, just as dropping the conditional part.
 
 Remember we're doing set theory stuff here. IMHO we should follow its 
 notation conventions as much as we can.

I'm well aware of what the full syntax is; being allowed to
write x instead of identity(x) is *not* a shortcut but
a perfectly straightforward unexceptional instance of the
usual syntax; list comprehensions already have neither the
syntax nor the semantics of set-theorists' comprehensions;
and in fact no set theorist would be at all troubled by seeing

{ x in S : predicate(x) }

which is the nearest equivalent in mathematical notation
for the abbreviated comprehension expressions being discussed.

Other than that, I quite agree :-).

-- 
g

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


RE: [Python-Dev] comprehension abbreviation (was: Adding any() an d all())

2005-03-14 Thread Batista, Facundo
Title: RE: [Python-Dev] comprehension abbreviation (was: Adding any() and all())





[Gareth McCaughan]


#- 1 Some bit of my brain is convinced that [x in stuff if condition]
#- is the Right Syntax and keeps making me type it even though
#- I know it doesn't work.


My brain says: 'x in stuff returns a bool, so we have [bool if condition]', and then my brain crash generating a core dump...

. Facundo


Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/



  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] comprehension abbreviation

2005-03-14 Thread Greg Ewing
Eric Nieuwland wrote:
The full syntax is:
[ f(x) for x in seq if pred(x) ]

being allowed to write 'x' instead of 'identity(x)' is already a 
shortcut,
That's a really strange way of looking at it. Unless
you would also say that
  x = y
is a shorthand for
  x = identity(y)
Not that it's false, it just seems like a completely
unnecessary layer of mental gymnastics...
--
Greg Ewing, Computer Science Dept, +--+
University of Canterbury,  | A citizen of NewZealandCorp, a   |
Christchurch, New Zealand  | wholly-owned subsidiary of USA Inc.  |
[EMAIL PROTECTED]  +--+
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] comprehension abbreviation (was: Adding any() and all())

2005-03-13 Thread Guido van Rossum
[Nick Coghlan]
  That 'x in seq' bit still shouts containment to me rather than
  iteration, though.
 
  Perhaps repurposing 'from':
 
(x from seq if f(x))
 
  That rather breaks TOOWTDI though (since it is essentially new syntax
  for a for loop). And I have other hopes for the meaning of (x from ()). . .

[Greg Ewing]
 How about:
 
(for x in seq if f(x))
 
 It still has the word 'for' in it and avoids mentioning
 x more times than necessary.
 
 Although I can't help feeling that it should be some
 other word instead, such as
 
(all x in seq if f(x))
 
 or
 
(every x in seq if f(x))

I doubt that we'll find a satisfactory solution for this issue. Here's why:

- We're only talking of a savings of 4 characters (plus two spaces) in
the best case, assuming the identifier can be a single letter (it's
scope is only the current expression anyway).

- Ping's proposal ('x in seq if f(x)') IMO loses for several reasons:
it would be a hugely ambiguous use of 'in', and would cut off a
possible future syntax for conditional expression(*): 'A if T else B'.

- The various improvements on Ping's proposal reduce the amount of
typing saved even more ('every' is actually longer than 'for x').

- Before anybody asks, I really do think the reason this is requested
at all is really just to save typing; there isn't the avoid double
evaluation argument that helped acceptance for assignment operators
(+= etc.), and I find redability is actually improved with 'for'.


(*) Pleas stop calling it 'ternary expression'. That doesn't explain
what it means. It's as if we were to refer to the + operator as
'binary expression'.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


RE: [Python-Dev] comprehension abbreviation (was: Adding any() andall())

2005-03-13 Thread Raymond Hettinger
[GvR]
  - Before anybody asks, I really do think the reason this is
requested
  at all is really just to save typing; there isn't the avoid double
  evaluation argument that helped acceptance for assignment operators
  (+= etc.), and I find redability is actually improved with 'for'.

{Neil Hodgson]
For me, the main motivation is to drop an unnecessarily repeated
 identifier. If you repeat something there is a chance that one of the
 occurrances will be wrong which is one reason behind the Don't Repeat
 Yourself principle.

It's not actually a repetition.  Instead, it is a precise expression of
what is to be returned.  The proposal adopts a custom syntax to handle
one possible return value (identity) as a default.  You're trading away
explictness, giving up on having a uniform syntax, and introducing more
than one way to do it (the current approach would still be valid).

The repeated expression argument carried more weight in the context of
augmented assignment where complex lvalues are common:  self.arr[i] +=
j.  For genexps and listcomps, simple loop variables are the norm.

Try applying the proposal to existing code.  I think you'll see that
you've gained nothing.



 The reader can more readily see that this is a
 filter expression rather than a transforming expression.

Personally, I find the proposed syntax to be difficult to parse.  It's a
step backwards.




-1  

Sorry, I deem the proposal to be horrendous and hope it gets trounced
before it gets out of hand.



Raymond
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] comprehension abbreviation (was: Adding any() and all())

2005-03-12 Thread Greg Ewing
Nick Coghlan wrote:
That 'x in seq' bit still shouts containment to me rather than 
iteration, though.

Perhaps repurposing 'from':
  (x from seq if f(x))
That rather breaks TOOWTDI though (since it is essentially new syntax 
for a for loop). And I have other hopes for the meaning of (x from ()). . .
How about:
  (for x in seq if f(x))
It still has the word 'for' in it and avoids mentioning
x more times than necessary.
Although I can't help feeling that it should be some
other word instead, such as
  (all x in seq if f(x))
or
  (every x in seq if f(x))
--
Greg
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] comprehension abbreviation (was: Adding any() and all())

2005-03-11 Thread Nick Coghlan
Jim Jewett wrote:
Note that the last x shouldn't have to be x.
[x in seq if f(x)] 

is by far my most common syntax error, and 

[x for x in seq if f(x)]
is always what I want instead.
That 'x in seq' bit still shouts containment to me rather than iteration, 
though.
Perhaps repurposing 'from':
  (x from seq if f(x))
That rather breaks TOOWTDI though (since it is essentially new syntax for a for 
loop). And I have other hopes for the meaning of (x from ()). . .

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com