Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Antoon Pardon Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Tue, 24 Nov 2015 19:45:11 +0100 Lines: 58 Message-ID: References: <8601c9af-a7d9-4642-ba1c-8edd1e4c3390@googlegroups.com> <56546985.8060704@rece.vub.ac.be> <56547337.4000709@rece.vub.ac.be> <56547C53.8030407@rece.vub.ac.be> <5654864E.2070906@rece.vub.ac.be> <56549324.8020607@rece.vub.ac.be> <56549F15.40206@rece.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de ligCrPJ7mwxUaGSs6ltz2gR8cjemMF9egmx0+5xgNStg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'context': 0.05; 'cpython': 0.05; 'defines': 0.07; 'differently': 0.07; 'definition,': 0.09; 'indeed,': 0.09; 'literal': 0.09; 'optional': 0.09; 'python:': 0.09; 'python': 0.10; 'interpreter': 0.15; 'value.': 0.15; '(3,': 0.16; '24,': 0.16; '42,': 0.16; 'enumerates': 0.16; 'grounds': 0.16; "isn't.": 0.16; 'lexical': 0.16; 'literal.': 0.16; 'literals': 0.16; 'notations': 0.16; 'received:adsl- dyn.isp.belgacom.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'token,': 0.16; 'wrote:': 0.16; 'byte': 0.18; 'else,': 0.18; '>>>': 0.20; '2015': 0.20; 'constant': 0.22; 'context.': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'define': 0.27; 'followed': 0.27; 'not.': 0.27; 'specifically': 0.28; 'values': 0.28; 'argue': 0.29; 'received:192.168.1.3': 0.29; 'types.': 0.29; 'starts': 0.29; 'code': 0.30; 'ourselves': 0.30; 'received:be': 0.30; 'related': 0.32; 'point': 0.33; 'url:python': 0.33; 'point,': 0.33; 'though.': 0.33; 'definition': 0.34; 'tue,': 0.34; 'list': 0.34; 'confirmed': 0.35; 'displays': 0.35; 'nov': 0.35; 'something': 0.35; 'according': 0.36; 'but': 0.36; 'too': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'wrong': 0.38; 'why': 0.39; 'sure': 0.39; 'received:192': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'url:3': 0.60; 'charset:windows-1252': 0.62; 'matter': 0.63; 'limit': 0.65; 'limited.': 0.67; 'therefore': 0.67; '10:32': 0.84; '13)': 0.84; 'pardon': 0.84; 'received:195.238': 0.84; 'schreef': 0.84; 'notion': 0.91; 'url:reference': 0.91 X-Belgacom-Dynamic: yes X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CWAQDnqVRW/9Xi9VENUYQOb75KgWUhhW4CgX0SAQEBAQEBAYU/AQEEeBELGAkWDwkDAgECAUUTBgICiC8IrR6MfYQjAQEBBwEBAQEBGgSGVIR+hDQBcoQSBZZQhSSIDZxLKAmEN3EBg2ABgUkBAQE User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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:99385 Op 24-11-15 om 18:53 schreef Ian Kelly: > On Tue, Nov 24, 2015 at 10:32 AM, Antoon Pardon > wrote: >> Op 24-11-15 om 17:56 schreef Ian Kelly: >> >>> >>>> So on what grounds would you argue that () is not a literal. >>> >>> This enumerates exactly what literals are in Python: >>> >>> https://docs.python.org/3/reference/lexical_analysis.html#literals >>> >>> I think it's a rather pedantic point, though. How are nuances of the >>> grammar at all related to user expectations? >>> >> >> I think that enumaration is too limited. The section starts with: >> >> Literals are notations for constant values of some built-in types. >> >> () satisfies that definition, which is confirmed by the byte code >> produced for it. > > Literals are a type of lexical token. All of the literals shown in > that section are, indeed, tokens. Now I would point you to the grammar > specification: > > https://docs.python.org/3/reference/grammar.html > > And specifically the "atom" rule, which defines both list displays and > list comprehensions (as well as literals) as being atoms. > Specifically, it parses () as the token '(', followed by an optional > yield_expr or testlist_comp, followed by the token ')'. In no way is > that a single token, nor therefore a literal. I think limiting literals to lexical tokens is too limited. Sure we can define them like that in the context of the python grammar, but I don't see why we should limit ourselves to such a definition outside that context. I see nothing wrong with regarding -42 as a literal while according to the python grammar it isn't. There is nothing wrong with the notion that a literal can be a compounded value. But no matter what you want to call it. The dis module shows that -42 is treated in exactly the same way as 42, which is treated exactly the same way as () or as (5, 8, 13) which is treated differently from [] or [5, 8, 13]. Whether you want to call it literals or something else, the fact remains that (3, 5, 8) is treated like -42 by the CPython interpreter and [3, 5, 8] is not. -- Antoon.