Path: csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.freenet.ag!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Convert list to another form but providing same information Date: Tue, 22 Mar 2016 11:58:38 +1100 Lines: 51 Message-ID: References: <1010f2cb-21f9-495b-8af4-03ad209b4c1e@googlegroups.com> <87bn67oayt.fsf@bsb.me.uk> <87oaa7mjyh.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de h8LpFhSRNYEhxzQXircSeA0eto+hThCWeqliKLURhRnQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'assignment': 0.07; 'expressions': 0.07; 'subject:form': 0.07; 'cc:addr:python-list': 0.09; '22,': 0.09; 'braces': 0.09; 'callback': 0.09; 'parsed': 0.09; 'second.': 0.09; 'statements': 0.09; 'subject:same': 0.09; 'python': 0.10; 'syntax': 0.13; 'argument': 0.15; 'subsequent': 0.15; '"invalid': 0.16; '"lambda"': 0.16; '"test"': 0.16; '(there': 0.16; '2016': 0.16; 'benefit.': 0.16; 'delimit': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function()': 0.16; 'lambda': 0.16; 'parentheses': 0.16; 'parse,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Convert': 0.16; 'syntactic': 0.16; 'them.)': 0.16; 'unhelpful': 0.16; 'wrote:': 0.16; 'debugging': 0.18; 'nested': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'first,': 0.20; '(the': 0.22; 'saying': 0.22; 'arguments': 0.22; 'am,': 0.23; 'code,': 0.23; 'code.': 0.23; 'errors': 0.23; 'forgot': 0.23; '(this': 0.24; 'header:In-Reply-To:1': 0.24; 'wondering': 0.25; 'subject:list': 0.26; 'sense': 0.26; 'error': 0.27; 'define': 0.27; 'followed': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'currently,': 0.29; 'if,': 0.29; 'indentation': 0.29; 'pile': 0.29; "i'm": 0.30; 'code': 0.30; "can't": 0.32; 'statement': 0.32; 'problem': 0.33; 'message.': 0.33; 'common': 0.33; 'instead,': 0.33; 'though.': 0.33; 'definition': 0.34; 'tue,': 0.34; 'handle': 0.34; 'list': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'could': 0.35; 'something': 0.35; 'expected': 0.35; "isn't": 0.35; 'but': 0.36; 'too': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'framework': 0.36; 'keyword': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'being': 0.37; 'done.': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'wrong': 0.38; 'means': 0.39; 'why': 0.39; 'goes': 0.39; 'test': 0.39; 'some': 0.40; 'term': 0.60; 'close': 0.61; "you'll": 0.61; 'further': 0.62; 'within': 0.64; 'places': 0.64; 'mar': 0.65; 'series': 0.65; 'hints': 0.66; 'situation': 0.67; 'production': 0.67; 'chrisa': 0.84; 'confusing': 0.84; "it'd": 0.84; 'presumably': 0.84; '{...}': 0.84; 'to:none': 0.91; 'imagine': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-transfer-encoding; bh=KPy/09dqouorgPM6N+FZIENh8wDu6DJ8aVaoGjH+6pc=; b=xx4oOLSNI7O7s96oPbexZ4CwfvQGWkTzB0yCRjiNMO5wgSb7NTdk0UlTfIwmup9pme WbDVID5BdyfkOmdxu5gDCiQh56O5/yD94tc3vN578sArxeIMLVKrR2yqz2pPm0dOrGBN gqqfV3/owwkVqgr+J+t3aAKe8NA8JsThQz9pcjsG9bAlVbkMDWoRmc6chTaMhhoKSVAa Z0Nw10aU90UH9wsIG9cF+42i6BLHWY2g5uWZI0BxotVJw8GdmYhFUIasfADZMx2kooD+ HseOWbexSd0A7ui5F73O4BumZSJhZ8aF5RP/isq+kqDeD7sRPsT8IQgZ3j3w3RbW5dvR V/5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc:content-transfer-encoding; bh=KPy/09dqouorgPM6N+FZIENh8wDu6DJ8aVaoGjH+6pc=; b=mlpnj7M/GPP9O9QUp/2fiQsp3Ji87QJmoKIzHcRg9RbYzKwZyXki6JV3MTjtj+XCxR Cw9zS5H9UkD1fl6VPr37aYn6KqvWPG1BzEwY5DARYtyKMoMCEjTxhhXetl9bnqlIy9lV 6r1PL/Xrv/cKtVeSO4vkwDF+XxZ2vh2/ffgX5tJeXNZMNpw7anHXuIUlx3xSpJXbkePT ykph4dChgsy6bWIj5vZ+yJvbxX05kMzWEFKfrnsmQaSH4KljVfY68Gkrb3oZc8jRvhMD BhhGmLW/HBL3yHMzybPX1jj9UaaCE/pRYi2+0v5/p2jOVcrjcB6ThqyUv0dLeqv+kZMk Qzig== X-Gm-Message-State: AD7BkJKoIBlDELmR66rlA0yZ4TfjKTp/2yEi0jRN0+4JPvw93drgZPgGpgiW0+T++EPfcqkQ17bE+D3vAyXqDA== X-Received: by 10.51.17.34 with SMTP id gb2mr15533733igd.13.1458608318771; Mon, 21 Mar 2016 17:58:38 -0700 (PDT) In-Reply-To: <87oaa7mjyh.fsf@bsb.me.uk> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105428 On Tue, Mar 22, 2016 at 11:31 AM, Ben Bacarisse wrot= e: > However, the explanation ("because Python=E2=80=99s syntactic framework c= an'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. A "suite" is a series of statements - in common parlance, a block of code. A "test" is a type of expression (there are a variety of these kind of things, and they define operator precedence). Part of the trickiness of permitting statements inside expressions is that it would get confusing - not that it'd be truly ambiguous and impossible to parse, but that small errors could result in peculiar misinterpretations of subsequent code, which means the error messages would be harder to understand. There are already a few places like that: functioncall( # ) # oops, forgot the close parenthesis name =3D value othername =3D othervalue You'll get a SyntaxError on the last line, despite it being functionally identical to the second. And it's just "invalid syntax", the most completely unhelpful message. (This situation is considered worthwhile, though. Named arguments and assignment both make way too much sense to break one of them.) Now imagine if every "lambda" in the code could result in the same kind of thing; currently, the keyword "lambda" must be followed by a (possibly empty) argument list and then an expression, which must either be entirely within one line, or have parentheses around it. If, instead, "lambda x:" introduced a suite, you'd have errors coming up much further down. Having full statement syntax inside an expression isn't always even a benefit. It's often a major cost to readability - just have a look at a big pile of JavaScript callback code some time. (Although, to be fair, function() {...} isn't the only readability problem there.) And it has a debugging cost that gets significantly higher when you don't have braces to delimit blocks. ChrisA