Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Fri, 20 Nov 2015 04:45:14 +1100 Lines: 33 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=UTF-8 X-Trace: news.uni-berlin.de KopMjxYTNTaHozH1eQ/VKQ6KP2z4ULQc9CppJYWjqMIg== 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; 'pycon': 0.03; 'value,': 0.03; 'defaults': 0.05; '(b)': 0.07; 'objects,': 0.07; 'cc:addr :python-list': 0.09; 'mutable': 0.09; 'instead.': 0.15; 'binding,': 0.16; 'comprehend': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'identities': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'saying.': 0.16; 'wrote:': 0.16; 'copied': 0.18; "shouldn't": 0.18; 'language': 0.19; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '(the': 0.22; 'do.': 0.22; '(a)': 0.22; 'am,': 0.23; 'header:In- Reply-To:1': 0.24; 'all.': 0.24; 'fri,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'device': 0.28; 'sure,': 0.29; 'objects': 0.29; 'allows': 0.30; 'post': 0.31; 'another': 0.32; "can't": 0.32; 'changing': 0.34; 'definition': 0.34; 'received:google.com': 0.35; 'identity': 0.35; 'nov': 0.35; 'something': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'being': 0.37; 'received:209.85.213': 0.37; 'late': 0.38; 'received:209': 0.38; 'where': 0.40; 'called': 0.40; 'some': 0.40; 'easy': 0.60; 'your': 0.60; 'avoid': 0.61; 'default': 0.61; 'discuss': 0.61; 'side': 0.62; 'linked': 0.63; 'please,': 0.63; 'different': 0.63; 'between': 0.65; 'capable': 0.65; 'soon': 0.65; '20,': 0.66; 'matter.': 0.66; 'fact,': 0.67; 'subject': 0.70; 'chrisa': 0.84; 'contains.': 0.84; 'to:none': 0.91; 'write:': 0.91 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-type; bh=sp2LmVnkDh5Mt3E9SQxC3YHBQU4MMw0CS0Muvlfv5uI=; b=bP5xFFYRRHpzjhgzKumqlciVTfAizPpzKxqENarani0H05SfBg+32jsrvY1HHzcJ8a ymibnEbkFi0KNRK4Z0B1rNdoavwZjpwBz7fCOdvCZttVMm0e80TNWkaE/v8hP4Nv1m29 ncFinWeMsWSgtjIoUr+2srpPiIn53oppkk0mi649h1EMShBbbnaDZh7KI3b7h1Kuizlz HMsVG3B/drnU1Din6UQFsIGR9/LQvMsx6aHb/9eXVhvF027uJh7MgEnuNsnI4YpeoTIH q3xBDuCzSwaEfzeFgJsl8iUMnjeAut3glRKZH9Gze/UN54yyQYcinBWtQ7ANXX8PsZhL MJaQ== X-Received: by 10.50.225.38 with SMTP id rh6mr14741522igc.13.1447955115048; Thu, 19 Nov 2015 09:45:15 -0800 (PST) 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:99076 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. 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. ChrisA