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


Groups > comp.lang.python > #105423

Re: Convert list to another form but providing same information

Path csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.python
Subject Re: Convert list to another form but providing same information
Date Tue, 22 Mar 2016 00:31:50 +0000
Organization A noiseless patient Spider
Lines 27
Message-ID <87oaa7mjyh.fsf@bsb.me.uk> (permalink)
References <1010f2cb-21f9-495b-8af4-03ad209b4c1e@googlegroups.com> <87bn67oayt.fsf@bsb.me.uk> <mailman.461.1458591209.12893.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
Injection-Info mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="4993"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/YhnTOl1nAOPZudwH4Ke67pkj+AHviI3U="
Cancel-Lock sha1:2l+Se8oGrC50mJiz5v+pLa0K6Z0= sha1:FtWO2S0TCLF/JNipapc1EDzfVHo=
X-BSB-Auth 1.c08e43763e4e5e3dc4e7.20160322003150GMT.87oaa7mjyh.fsf@bsb.me.uk
Xref csiph.com comp.lang.python:105423

Show key headers only | View raw


Ian Kelly <ian.g.kelly@gmail.com> writes:

> On Mon, Mar 21, 2016 at 2:03 PM, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>> For experts here: why can't I write a lambda that has a statement in it
>> (actually I wanted two: lambda l, i: l[i] += 1; return l)?
>
> https://docs.python.org/3/faq/design.html#why-can-t-lambda-expressions-contain-statements

Thanks.  That makes it clear that it's just for syntactic and not
semantic reasons.

However, the explanation ("because Python’s syntactic framework can't
handle statements nested inside expressions") seemed, at first, to be
saying you can't because you can't!  But the term "syntactic framework"
hints that it's not really just an arbitrary choice -- that this is
something about the way Python is parsed that make this choice
inevitable.  Is it to do with the way that indentation has a syntactic
role?

To phrase my question in terms of syntax, why is the : in lambda
followed by a test (the top-level production for an expression in the
grammar) but the : in a function definition is followed by a suite?  I
expected them to be both a suite, but presumably something goes horribly
wrong if that were done.  Now I'm wondering what.

-- 
Ben.

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


Thread

Convert list to another form but providing same information Maurice <mauricioliveiraguarda@gmail.com> - 2016-03-21 11:26 -0700
  Re: Convert list to another form but providing same information Maurice <mauricioliveiraguarda@gmail.com> - 2016-03-21 11:30 -0700
    Re: Convert list to another form but providing same information Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-21 19:24 +0000
    Re: Convert list to another form but providing same information anantguptadbl@gmail.com - 2016-03-22 07:23 -0700
  Re: Convert list to another form but providing same information Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-21 19:21 +0000
  Re: Convert list to another form but providing same information Peter Otten <__peter__@web.de> - 2016-03-21 20:22 +0100
  Re: Convert list to another form but providing same information Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-21 20:03 +0000
    Re: Convert list to another form but providing same information Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-21 14:12 -0600
      Re: Convert list to another form but providing same information Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-22 00:31 +0000
        Re: Convert list to another form but providing same information Chris Angelico <rosuav@gmail.com> - 2016-03-22 11:58 +1100
        Re: Convert list to another form but providing same information Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-03-22 15:34 +1100
    Re: Convert list to another form but providing same information Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-21 14:14 -0600
  Re: Convert list to another form but providing same information Steven D'Aprano <steve@pearwood.info> - 2016-03-22 11:13 +1100
  Re: Convert list to another form but providing same information Paul Rubin <no.email@nospam.invalid> - 2016-03-21 18:35 -0700
    Re: Convert list to another form but providing same information Steven D'Aprano <steve@pearwood.info> - 2016-03-22 21:49 +1100

csiph-web