Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Fri, 20 Nov 2015 09:16:45 -0700 Lines: 34 Message-ID: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> <564e71f6$0$1619$c3e8da3$5496439d@news.astraweb.com> <877flcrh26.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de 3nfu//RKaoXnBycLsWzU3AsdyP6ROUg9p5Xw+4rcZAgQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:209.85.223': 0.03; 'semantics': 0.09; 'def': 0.13; 'explicitly': 0.15; 'value.': 0.15; '(lambda': 0.16; 'lambda': 0.16; 'omitted,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'rewritten': 0.16; 'sentinel': 0.16; 'value:': 0.16; 'values:': 0.16; 'wrote:': 0.16; "shouldn't": 0.18; '2015': 0.20; 'pass': 0.22; 'am,': 0.23; 'needed.': 0.23; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'data,': 0.27; 'function': 0.28; 'values': 0.28; 'argue': 0.29; 'omitted': 0.29; 'allows': 0.30; 'point': 0.33; 'values.': 0.33; 'received:google.com': 0.35; 'could': 0.35; 'nov': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'possible': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'version': 0.38; 'received:209': 0.38; 'or,': 0.38; 'rather': 0.39; 'to:addr:python.org': 0.40; 'default': 0.61; 'more': 0.63; 'between': 0.65; '20,': 0.66; 'here': 0.66; 'as:': 0.79; 'distinguish': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=b2xshgO2NV1YwEkKnXLXU/IZXzzhQsPbuswJSay6Mnk=; b=w9h16kOV+IdjhUZKCbPgeAp25YDuOZpdOt175IC1bx1sQxnKcVN7zyC47IWSWhlKZQ 2SwJanfieLk3pRn25wL0g2JYxiT+ND62/YNOUVJLXHB/F1zx5bTYa5TpAieZxbQ4tILH zNuSObwXHdGWmft7riZIbtsvkW1gSdRMfpHIcF1Ld7tvjO6+FgIK0cjO0cC40DTjzsC1 R+hBgTxxXasC4ol4IxdmNZ5/6Sz2knJMp0a1iC0F3dIW1VhhrhNYQwXcUzf0vjfAw2Ly qD+TJj8Eq9fdYAzZmiGzU9PZgpD19L8HNBTAi+mYKIbFVkuuwqgaiQg3YEjrpPYDbNpB KKoQ== X-Received: by 10.107.164.154 with SMTP id d26mr14654884ioj.111.1448036245734; Fri, 20 Nov 2015 08:17:25 -0800 (PST) In-Reply-To: <877flcrh26.fsf@elektro.pacujo.net> 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:99161 On Fri, Nov 20, 2015 at 5:28 AM, Marko Rauhamaa wrote: > The Ackermann function really is an esoteric example, but the other > example that has been discussed here can make practical use of the > default-value semantics: > > [ lambda x: i * x for i in range(4) ] > > which is salvaged with a default value: > > [ lambda x, i=i: i * x for i in range(4) ] > > or, more hygienically: > > [ (lambda i=i: lambda x: i * x)() for i in range(4) ] Note that this last version could be rewritten as: [ (lambda i: lambda x: i * x)(i) for i in range(4) ] At which point the default value semantics are no longer needed. > One could argue that you should always use a sentinel object for default > values. That also allows you to distinguish between omitted values and > default values: > > def asklist(caption, data, n=omitted, rows=omitted, width=omitted, > flags=omitted, buttons=omitted, tablist=omitted, > heading=omitted): > > but that would be rather pedantic in most circumstances. I think that would be bad design; in general, you shouldn't *need* to distinguish whether the value was omitted, because it should always be possible to explicitly pass the default value.