[Python-bugs-list] [ python-Feature Requests-453677 ] statements should return a value

SourceForge.net noreply@sourceforge.net
Mon, 12 May 2003 18:49:37 -0700


Feature Requests item #453677, was opened at 2001-08-21 04:07
Message generated for change (Comment added) made by bcannon
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=453677&group_id=5470

Category: None
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: statements should return a value

Initial Comment:
In the Ruby language all constructs have a value. For 
example an if-construct returns a value, so you can use 
if also on the right side of an expression. 

I think that it would be really great to have the same 
in Python. That would permit to:

#1 emulate the C ternary operator ?:
y= 10 * if x>0 : 1 else : -1  
I find it more intuitive than the a and b or c construct 
and drop out the b==0 bug
The only potential problem is operator priority:
should y = if x%2: x+1 else: x/2     mean :
(a)  y =  if x%2: (x+1) else: (x/2)   or
(b)  y =  (if x%2: x+1 else: x)/2
I think (a) is the right answer

#2 replace lambda statement
f= def x,y : x+y
This new syntax of def statement could permit to create 
anonymous functions. Because the classical def f(x): 
statement will now returning a value, this would be 
really intuitive and permit to reduce the number of 
concepts in the language (instead of def and lambda  
statements, we will have only def statements with 
optional function name specification)

#3 make list completion more linked with the language
List completion is really useful but it's syntax is not 
very consistent with the language.
Now we could have:
Squares = for i in range(10): i**2
Sequence = for i in range(10): 
              if i%2 : 3*i+1 else: i/2
 
One potential problem is filtering:
We want that:
(for i in range(5): if i%2 : i) == (1,3)
(for i in range(5): if i%2 : i else : None) == 
(None,1,None,3,None)
i=4; (if i%2 : i) == None
One solution would be to create a new value NO_RET_VAL 
wich is returned by the if statement when no else have 
been executed. This value is automatically converted to 
None except when it is caught by a for or a while 
statement.


----------------------------------------------------------------------

>Comment By: Brett Cannon (bcannon)
Date: 2003-05-12 18:49

Message:
Logged In: YES 
user_id=357491

No way.  We do not need people to suddenly start doing assignment in 'if' 
statements like C.  I know for a fact there is no way that this is going to 
happen, *ever*.  I am going to close and reject this.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=453677&group_id=5470