[issue1714448] if something as x:

2009-03-15 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

Rejecting this after discussion on python-ideas:
http://mail.python.org/pipermail/python-ideas/2009-March/003423.html

Overview of some of the major objections here:
http://mail.python.org/pipermail/python-ideas/2009-March/003440.html

--
nosy: +ncoghlan
resolution:  - rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1714448
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1714448] if something as x:

2009-03-15 Thread Matthew Barnett

Matthew Barnett pyt...@mrabarnett.plus.com added the comment:

Just for the record, I wasn't happy with ~= either, and I have no
problem with just forgetting the whole idea.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1714448
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1714448] if something as x:

2009-03-14 Thread Jervis Whitley

Jervis Whitley jervi...@gmail.com added the comment:

Hi, 

I like this idea. 

I've put together a short patch that will implement inline
assignment. 

if f() - name:
  use(name)

or more powerfully:

if f() - name == 'spam':
   usespam(name)

the old syntax if something as x: is still available if that
is what is desired.

if (f() == 'spam') - name:
   newname = name.replace('p', 'h') 

Patched against Py3k please kick the tires, I've added some tests and
developed a PEP.

--
keywords: +patch
nosy: +jdwhitley
versions: +Python 3.1 -Python 2.6
Added file: http://bugs.python.org/file13329/assexp.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1714448
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1714448] if something as x:

2009-03-14 Thread Steven D'Aprano

Steven D'Aprano st...@pearwood.info added the comment:

Regarding the proposed syntax:

if (f() == 'spam') - name:
   newname = name.replace('p', 'h') 

Surely that should assign the *bool* result of comparing f() 
with 'spam' to name? Doing anything else is opening the door to a 
world of pain.

if (f() == 'spam') - name  # binds name=f()
if ('spam' == f()) - name  # binds 'spam' to name?
if (f() == g()) - name  # binds what to name?
if (f() or g()) - name  # binds what to name?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1714448
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1714448] if something as x:

2009-03-14 Thread Jervis Whitley

Jervis Whitley jervi...@gmail.com added the comment:

 If we allow this, how many of the following will be allowed?

 if expr as name: block
 while expr as name: block
 expr as name  # alternative to name = expr

This patch implements your final point:
 expr as name (albeit with a nominal '-' RARROW rather than 'as')

the patch creates a new expression, assexp (assignment expression) 
there is no need to implement this for countless other 
if/while/for because
they accept expressions and this assignment is an expression.
(Note it is a patch for a different behaviour than the OP suggested.)


 As for using -, please no, there are plenty of languages that use 
 line noise, but Python doesn't need to be one of them.

I have begun a discussion about this on python-ideas to give it some
air as suggested by Raymond. We can always close the issue as 'wont fix'
if it doesn't get off the ground. 

This issue (although addressing an old concern dating back 
to the beginning of python) has been sitting unloved for 9 or so months
and I felt that we should at least resolve it.

Cheers, 

Jervis

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1714448
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1714448] if something as x:

2009-03-14 Thread Jervis Whitley

Jervis Whitley jervi...@gmail.com added the comment:

 Regarding the proposed syntax:

 if (f() == 'spam') - name:
   newname = name.replace('p', 'h') 

 Surely that should assign the *bool* result of comparing f() 
 with 'spam' to name? Doing anything else is opening the door to a 
 world of pain.

You are correct. It does assign the result of the bool. I have
made an error in creating the example. This is what happens when
I copy and paste and don't check the result.

should read

 if f - name:
   # use name, (pointless example but in line with the OP's suggestion)

Thanks for picking this up.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1714448
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1714448] if something as x:

2009-03-14 Thread Matthew Barnett

Matthew Barnett pyt...@mrabarnett.plus.com added the comment:

At the moment binding occurs either right-to-left with =, eg.

x = y

where x is the new name, or left-to-right, eg.

import x as y

where y is the new name.

If the order is to be right-to-left then using as seems to be the best
choice.

On the other hand, if there should be a form of binding explicitly for
use in an expression in order to prevent accidental use of = then the
order should probably be the same as =, ie right-to-left, and a new
symbol is needed (using punctuation feels preferable somehow, because
= uses punctuation).

The only symbol I can think of is ~=.

How does this:

if ob ~= map[x][y].overpay:
   ob.blit(x, y)

look compared to:

if map[x][y].overpay as ob:
   ob.blit(x, y)

IMHO, of course.

--
nosy: +mrabarnett

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1714448
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1714448] if something as x:

2009-03-14 Thread Steven D'Aprano

Steven D'Aprano st...@pearwood.info added the comment:

Matthew suggested ~= instead of - or as.

I dislike this because ~= first makes me think of approximately equal 
to, and then it makes me think of augmented assignment, and only then 
do I remember that although ~ is used in Python for bitwise-not, ~= is 
not a legal augmented assignment.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1714448
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com