Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Mark Lawrence Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Thu, 19 Nov 2015 18:26:08 +0000 Lines: 64 Message-ID: References: <564dbe6b$0$1610$c3e8da3$5496439d@news.astraweb.com> <564df258$0$1604$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de ogtamiCQqQ62s6aGzhMJXQ36FRBcmcQSlumphoJJPGWw== 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; 'python,': 0.02; 'pycon': 0.03; 'value,': 0.03; 'compiler': 0.05; 'defaults': 0.05; 'from:addr:yahoo.co.uk': 0.05; '(b)': 0.07; 'default.': 0.07; 'objects,': 0.07; 'mutable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'through,': 0.09; 'argument': 0.15; 'instead.': 0.15; 'binding,': 0.16; 'comprehend': 0.16; 'constructs': 0.16; 'identities': 0.16; 'nick': 0.16; 'omitted,': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'saying.': 0.16; 'substitute': 0.16; 'summarize,': 0.16; 'webmaster.': 0.16; 'wrote:': 0.16; 'looked': 0.16; 'copied': 0.18; "shouldn't": 0.18; 'language': 0.19; '>>>': 0.20; '2015': 0.20; '(the': 0.22; 'do.': 0.22; '(a)': 0.22; "aren't": 0.22; 'lawrence': 0.22; "world's": 0.22; 'am,': 0.23; 'bit': 0.23; "haven't": 0.24; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'header:X -Complaints-To:1': 0.26; 'chris': 0.26; 'followed': 0.27; 'fri,': 0.27; 'function': 0.28; 'idea': 0.28; 'device': 0.28; 'about.': 0.29; 'sure,': 0.29; 'objects': 0.29; 'allows': 0.30; 'post': 0.31; 'another': 0.32; "can't": 0.32; 'knows': 0.32; 'language.': 0.32; 'club': 0.33; 'right?': 0.33; 'values.': 0.33; 'changing': 0.34; 'definition': 0.34; 'languages': 0.34; 'lists': 0.34; 'identity': 0.35; 'nov': 0.35; 'knowledge': 0.35; 'something': 0.35; "isn't": 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'being': 0.37; 'received:org': 0.37; 'late': 0.38; 'to:addr:python.org': 0.40; 'where': 0.40; 'mark': 0.40; 'called': 0.40; 'some': 0.40; 'easy': 0.60; 'your': 0.60; 'leading': 0.61; 'avoid': 0.61; 'default': 0.61; 'discuss': 0.61; 'side': 0.62; 'charset:windows-1252': 0.62; 'linked': 0.63; 'please,': 0.63; 'different': 0.63; 'our': 0.64; 'between': 0.65; 'capable': 0.65; 'soon': 0.65; '20,': 0.66; 'matter.': 0.66; 'fact,': 0.67; 'talking': 0.67; 'subject': 0.70; 'directly.': 0.76; 'article': 0.77; 'exclusive': 0.81; 'contains.': 0.84; 'pythonistas,': 0.84; 'remarks': 0.84; 'rue': 0.84; 'write:': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 195.147.230.164 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.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:99080 On 19/11/2015 18:19, BartC wrote: > On 19/11/2015 17:45, Chris Angelico wrote: >> On Fri, Nov 20, 2015 at 4:30 AM, BartC wrote: >>> The whole concept of 'mutable' default is alien to me. A default is >>> just a >>> convenient device to avoid having to write: >>> >>> fn(0) or fn("") or fn([]) >>> >>> You just write fn() instead. But it shouldn't come at the cost of >>> completely >>> different semantics! Because then it can't really be called a default >>> value >>> at all. >>> >> >> Do you understand the concept of "mutable objects"? Don't even try to >> discuss mutable function defaults until you do. > > Yes. In the languages I create, pretty much everything is mutable, > provided it can supply an l-value. Constructs such as those for empty > lists ([] in Python, () in mine) aren't l-values. > > But it doesn't apply default values. The language is very different > however, because the byte-code compiler always has full knowledge of > functions that are called directly. Then it knows when an argument is > omitted, and can simply substitute the expression used as the default. > >> If your language simply has no mutable objects, then sure, it's easy >> to understand function defaults! There's no such thing as early or >> late binding; in fact, you can even super-late-bind, where you don't >> actually call a function until its *return value* is being used (as >> long as that function has no side effects). But as soon as objects are >> capable of retaining their identities while changing their values, you >> need an object model that (a) distinguishes between identity and >> value, and (b) allows some definition of early or late binding, >> because it *will* matter. >> >>> if you write A=B then something of B needs to have been copied into >>> A, even if it's just the reference that B contains. Otherwise it >>> would be >>> difficult to get A to refer to the same object as B. >> >> Please, PLEASE, go and read/watch Ned's PyCon talk (the one I linked >> you to earlier). Don't post another word on this subject until you >> comprehend what he is saying. > > I looked through the long article (I don't remember seeing a link to a > video), and followed it up to about 3/4 of the way through, then it got > a bit heavy. > > But what is it about my remarks above that isn't right? > To summarize, it once again shows that you haven't got the faintest idea what you're talking about. You're now in a very exclusive club with the RUE and Nick the Greek, the world's leading webmaster. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence