[Python-ideas] Combining test and assignment

Serhiy Storchaka storchaka at gmail.com
Sun Jan 22 19:02:40 CET 2012

22.01.12 14:04, Paul Moore написав(ла):
> While in general I agree with you, there *is* a natural reading of this:
> "if spam() isn't 'ham', frobulate it"
> The fact that you have to choose a name is because computer languages
> have to be more explicit than natural languages, and can't deal with
> the implicit referent involved in the English usage of "it". The need
> for assignment comes from the need for a name. You could actually deal
> with the if-or-while-expression-assignment case by defining a special
> variable __it__ to mean the value of the condition in the containing
> if or while expression, but it has all the same lack of generality
> issues as any proposal that limits itself to if/while conditions. And
> short of explicitly marking the expression somehow, you can't
> generalise any further.

Kotlin (http://confluence.jetbrains.net/display/Kotlin/Kotlin) has "it":

names filter {it.startsWith("A")} sortby {it} map {it.toUpperCase()} 
foreach {print(it)}

More information about the Python-ideas mailing list