while expression feature proposal

Cameron Simpson cs at zip.com.au
Fri Oct 26 18:03:39 EDT 2012


On 26Oct2012 09:10, Paul Rubin <no.email at nospam.invalid> wrote:
| However, if the "as" can be part of an expression as in Chris Angelico's
| post, Chris's suggestion
| 
|      while (client.spop("profile_ids") as profile_id) is not None:
|          print profile_id
| 
| looks good to me.

Now this pulls me from a -0 to a +0.5.

Instead of burdening the control constructs with further structure, make
"as" a binding operation for keeping intermediate results from expressions.

It will work anywhere an expression is allowed, and superficially
doesn't break stuff that exists if "as" has the lowest precedence.

Any doco would need to make it clear that no order of operation is
implied, so that this:

  x = 1
  y = (2 as x) + x

does not have a defined answer; might be 2, might be 3. Just like any
other function call with side effects.

Speaking for myself (of course!), I definitely prefer this to adding
"as" as a post expression struction on if/while/etc.

I'm not +1 because to my mind it still presents a way for
assignment/binding to not be glaringly obvious at the left hand side of
an expression.

It would probably mean folding the except/with "as" uses back into
expressions and out of the control-structural part of the grammar. I can't
see that that would actually break any existing code though - anyone else?

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

UNIX was not designed to stop you from doing stupid things, because that
would also stop you from doing clever things.   - Doug Gwyn



More information about the Python-list mailing list