Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32241

Re: while expression feature proposal

References <7xlietjjsd.fsf@ruckus.brouhaha.com> <20121026220338.GA25126@cskk.homeip.net>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-10-26 16:48 -0600
Subject Re: while expression feature proposal
Newsgroups comp.lang.python
Message-ID <mailman.2911.1351291717.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Oct 26, 2012 at 4:03 PM, Cameron Simpson <cs@zip.com.au> wrote:
> It will work anywhere an expression is allowed, and superficially
> doesn't break stuff that exists if "as" has the lowest precedence.

Please, no.  There is no need for it outside of while expressions, and
anywhere else it's just going to be bad practice.  Even if it's
considered an expression, let's only allow it in while expressions.

> 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.

Actually, the docs are clear that expressions are evaluated left to
right, so the expected result of the above would be 4.

> 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?

Yes it would, because the meaning is a bit different in both of those
cases.  For except, the result of the expression (an exception class
or tuple of classes) is not stored in the target; the exception
*instance* is.  Similarly for with, the result of the expression is
not stored; the result of calling its __enter__ method is, which is
often but not always the same thing.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-24 16:54 -0600
  Re: while expression feature proposal Paul Rubin <no.email@nospam.invalid> - 2012-10-24 16:08 -0700
    Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-24 17:39 -0600
      Re: while expression feature proposal Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-25 09:21 +0200
        Re: while expression feature proposal Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-25 12:12 +0200
        Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-25 10:36 -0600
          Re: while expression feature proposal Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-25 22:49 +0200
            Re: while expression feature proposal Dan Loewenherz <dloewenherz@gmail.com> - 2012-10-25 22:12 -0700
              Re: while expression feature proposal Paul Rubin <no.email@nospam.invalid> - 2012-10-25 23:06 -0700
                Re: while expression feature proposal Chris Angelico <rosuav@gmail.com> - 2012-10-26 17:23 +1100
                Re: while expression feature proposal Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-26 09:43 +0000
                Re: while expression feature proposal Dan Loewenherz <dloewenherz@gmail.com> - 2012-10-26 08:29 -0700
                Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-26 09:42 -0600
                Re: while expression feature proposal Paul Rubin <no.email@nospam.invalid> - 2012-10-26 09:10 -0700
                Re: while expression feature proposal Cameron Simpson <cs@zip.com.au> - 2012-10-27 09:03 +1100
                Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-26 16:48 -0600
                Re: while expression feature proposal Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-27 00:07 +0000
                Re: while expression feature proposal Paul Rubin <no.email@nospam.invalid> - 2012-10-26 20:43 -0700
                Re: while expression feature proposal Tim Chase <sed@thechases.com> - 2012-10-26 18:26 -0500
                Re: while expression feature proposal Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 19:41 -0400
                Re: while expression feature proposal Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 19:19 -0400
                Re: while expression feature proposal Chris Angelico <rosuav@gmail.com> - 2012-10-27 11:42 +1100
              Re: while expression feature proposal Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 19:12 -0400
                Re: while expression feature proposal Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-27 00:18 +0000
                Re: while expression feature proposal Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 20:27 -0400
                Re: while expression feature proposal Tim Chase <python.list@tim.thechases.com> - 2012-10-27 14:15 -0500
              Re: while expression feature proposal Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 19:51 -0400
        Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-25 10:47 -0600
    Re: while expression feature proposal Paul Rudin <paul.nospam@rudin.co.uk> - 2012-10-25 10:35 +0100

csiph-web