python3: accessing the result of 'if'
Carl Banks
invalidemail at aerojockey.com
Sun Jan 9 02:35:29 EST 2005
Donn Cave wrote:
> If Python 3 is going to get assignment-as-expression, it will be
> because GvR accepts that as a reasonable idea. You won't bootleg it
> in by trying to hide it behind this "where" notion, and you're not
> doing "where" any good in trying to twist it this way either.
I suspect you misunderstood me. When proposed this:
. if m > 20 where m=something():
. use(m)
the "where m=something()" part is NOT part of the if-expression. It is
an optional part of the if-statement. A very poor excuse for a BNF
grammar of the if-statment would look like this:
. "if" expr [ "where" symbol "=" expr ] suite ...
In no way, shape, or form did I ever intend for something like this to
be possible:
. x = (m > 20 where m=something())
Besides, if I had intended it to be an alternately-spelled assignment
expression, then it wouldn't have worked as I stated. I wanted the
thing being bound to be visible inside the if-expression and the
if-block, and to do that it must have the cooperation of the if-block,
and therefore must be part of the if-statement. If this were an
assigment expression, then m would have to be either be visible within
the whole surrounding scope, or just within that expression.
What I proposed was really nothing more than a convenient way to sneak
an extra binding inside an elif clause. (The real point here is not to
use this on if-clauses, but on elif-clauses.)
--
CARL BANKS
More information about the Python-list
mailing list