statements in control structures (Re: Conditional Expressions don't solve the problem)
Anders J. Munch
andersjm at dancontrol.dk
Thu Oct 18 09:36:07 EDT 2001
"Huaiyu Zhu" <huaiyu at gauss.almadan.ibm.com> wrote in message
news:slrn9sruhl.ll.huaiyu at gauss.almadan.ibm.com...
> I've been writing this for several evenings. It's not polished, but IMHO
it
> solves most of the problems discussed in this thread. So here it goes.
:-)
>
>
> PEP: Statements in Control Structures
Here's an additional alternative:
Use a function-like form let to perform assignment within expression.
let(X,Y)
has the effect of doing
X = Y
and returning the assigned object.
Example:
from sys import let
while let(x, get_next()):
process(x)
Issues:
=======
* Syntax errors.
No new syntax to worry about.
* Obuscation.
- Python function do not usually modify caller variables.
+ A reader of this code who doesn't know let can find out about it using
through the usual mechanism, sys.let.__doc__.
* Compatibility.
No compatibility issues; let is not a keyword.
* Generality.
Doesn't allow arbitrary statements to be executed.
Does allow short circuit conditions.
* Implementation.
Hackish. Introducing a let keyword would be cleaner.
- Anders
More information about the Python-list
mailing list