Issue1114404
Created on 2005-02-02 01:27 by ldrhcp, last changed 2005-02-02 23:08 by goodger.
| Messages (2) | |||
|---|---|---|---|
| msg54364 - (view) | Author: Lenny Domnitser (ldrhcp) | Date: 2005-02-02 01:27 | |
Python should allow a return value for some statements
or blocks such as `print` or `def`. This should not
always happen, but could certainly be useful.
This can be used instead of lambdas when something more
complex is required (the `def` example.)
What seems to me to be the most natural syntax is to
simply wrap the statement in parentheses. For example:
>>> foo = (print 'bar')
bar
>>> foo
'bar'
>>> f = (def f(x):
if x < 0:
return -5
return x ** 2 )
>>> f
<function f at 0x00A575B0>
>>> # A useful example:
>>> do_some_sort_of_logging( ( raise SomeSortOfError ) )
It will generally be obvious what should be returned,
but why not be more explicit? Here are some loose specs:
`def` would return the defined function.
`class` would return the defined class.
`print` would return the string representation of the
printed object.
`raise` will return the exception.
`import` returns the module or a tuple of modules.
This is not mean to be complete or a definitive syntax,
but I'd certainly like this discussed and something
along the lines of this proposal implemented.
|
|||
| msg54365 - (view) | Author: David Goodger (goodger) | Date: 2005-02-02 23:08 | |
Logged In: YES user_id=7733 In Python, expressions return values. Statements don't. That's fundamental to the language. In any case, such a proposal is too broad to discuss here. If you'd like to proceed, please write a PEP. See http://www.python.org/peps/pep-0001.html for the procedure. Better yet, please discuss it on comp.lang.python (python-list@python.org) first. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2005-02-02 01:27:25 | ldrhcp | create | |