Re: functions, list, default parameters

2010-11-09 Thread Mark Wooding
Lawrence D'Oliveiro writes: > In message , Robert Kern > wrote: > > So examining LHS "selectors" is not sufficient for determining > > immutability. > > Yes it is. All your attempts at counterexamples showed is that it is not > necessary, not that it is not sufficient. You've got them the wron

Re: functions, list, default parameters

2010-11-08 Thread Robert Kern
On 11/8/10 5:24 PM, Lawrence D'Oliveiro wrote: In message, Robert Kern wrote: On 11/4/10 2:07 AM, Lawrence D'Oliveiro wrote: In message, Robert Kern wrote: On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: In message, Robert Kern wrote: "Immutable objects" are just those without an obvious

Re: functions, list, default parameters

2010-11-08 Thread Lawrence D'Oliveiro
In message , Robert Kern wrote: > On 11/4/10 2:07 AM, Lawrence D'Oliveiro wrote: > >> In message, Robert >> Kern wrote: >> >>> On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: >>> In message, Robert Kern wrote: > "Immutable objects" are just those without an obvious API for >

Re: functions, list, default parameters

2010-11-08 Thread Roy Smith
In article , Lawrence D'Oliveiro wrote: > In message <20101021235138.609fe...@geekmail.invalid>, Andreas Waldenburger > wrote: > > > While not very commonly needed, why should a shared default argument be > > forbidden? > > Because it’s safer to disallow it than to allow it. The best way t

Re: functions, list, default parameters

2010-11-08 Thread John Ladasky
On Nov 1, 7:30 pm, Lawrence D'Oliveiro wrote: > In message <20101021235138.609fe...@geekmail.invalid>, Andreas Waldenburger > wrote: > > > While not very commonly needed, why should a shared default argument be > > forbidden? > > Because it’s safer to disallow it than to allow it. That's why Java

Re: functions, list, default parameters

2010-11-07 Thread alex23
m...@distorted.org.uk (Mark Wooding) wrote: > And the advantage of all of this typing over ['missing'] is what, > precisely? No chance of the sentinel object being accidentally mutated would be the big one for me, but clarity of intent would be a close second. -- http://mail.python.org/mailman/l

Re: functions, list, default parameters

2010-11-06 Thread Steven D'Aprano
On Sat, 06 Nov 2010 12:37:42 +, Mark Wooding wrote: >> > _missing = ['missing'] >> >> A curious choice for the sentinel value. We're not using Python 1.5 any >> longer > > Two reasons. Firstly, this comes from my Lisp background: making a list > is the obvious way of producing an unf

Re: functions, list, default parameters

2010-11-06 Thread Mark Wooding
Dennis Lee Bieber writes: > On Sat, 06 Nov 2010 12:37:42 +, m...@distorted.org.uk (Mark Wooding) > declaimed the following in gmane.comp.python.general: > > > > > Two reasons. Firstly, this comes from my Lisp background: making a > > list is the obvious way of producing an unforgeable objec

Re: functions, list, default parameters

2010-11-06 Thread Mark Wooding
Steven D'Aprano writes: > On Fri, 05 Nov 2010 12:17:00 +, Mark Wooding wrote: > > Right; so a half-decent compiler can notice this and optimize > > appropriately. Result: negligible difference. > > Perhaps the biggest cost is that now your language has inconsistent > semantics: some functio

Re: functions, list, default parameters

2010-11-05 Thread Steven D'Aprano
On Fri, 05 Nov 2010 12:17:00 +, Mark Wooding wrote: >> #1 Most default values are things like True, False, None, integer or >> string literals. Since they're literals, they will never change, so you >> only need to set them once. > > Right; so a half-decent compiler can notice this and optimi

Re: functions, list, default parameters

2010-11-05 Thread Mark Wooding
Steven D'Aprano writes: > defaults initialise on function definition (DID) > defaults initialise on function call (DIC) > > I claim that when designing a general purpose language, DID (Python's > existing behaviour) is better than DIC: > > #1 Most default values are things like True, False, None

Re: functions, list, default parameters

2010-11-05 Thread Steven D'Aprano
On Thu, 04 Nov 2010 22:34:07 +, Mark Wooding wrote: > (Based on experience with other languages, I suspect that evaluating the > default expression afresh for each call where it's needed would be more > useful; but it's way too late to change that now.) Let's call the two strategies: default

Re: functions, list, default parameters

2010-11-04 Thread Mark Wooding
Lawrence D'Oliveiro writes: > Mediocre programmers with a hankering towards cleverness latch onto it > as an ingenious way of maintaing persistent context in-between calls > to a function, completely overlooking the fact that Python offers much > more straightforward, comprehensible, flexible, an

Re: functions, list, default parameters

2010-11-04 Thread Mark Wooding
Lawrence D'Oliveiro writes: > In message <20101021235138.609fe...@geekmail.invalid>, Andreas > Waldenburger wrote: > > While not very commonly needed, why should a shared default argument be > > forbidden? > > Because it’s safer to disallow it than to allow it. Scissors with rounded ends are saf

Re: functions, list, default parameters

2010-11-04 Thread Robert Kern
On 11/4/10 2:07 AM, Lawrence D'Oliveiro wrote: In message, Robert Kern wrote: On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: In message, Robert Kern wrote: "Immutable objects" are just those without an obvious API for modifying them. They are ones with NO legal language constructs for mod

Re: functions, list, default parameters

2010-11-04 Thread Lawrence D'Oliveiro
In message , Robert Kern wrote: > On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: > >> In message, Robert >> Kern wrote: >> >>> "Immutable objects" are just those without an obvious API for modifying >>> them. >> >> They are ones with NO legal language constructs for modifying them. Hint: >> if a

Re: functions, list, default parameters

2010-11-03 Thread Bruno Desthuilliers
Lawrence D'Oliveiro a écrit : In message <20101021235138.609fe...@geekmail.invalid>, Andreas Waldenburger wrote: While not very commonly needed, why should a shared default argument be forbidden? Because it’s safer to disallow it than to allow it. Then there are quite a few python features

Re: functions, list, default parameters

2010-11-03 Thread Hrvoje Niksic
Paul Rudin writes: > Terry Reedy writes: > >> Suppose I write an nasty C extension that mutates tuples. What then >> would be illegal about... > > Depends on exactly what we mean by legal. If immutability is part of the > language spec (rather than an artifact of a particular implementation) > t

Re: functions, list, default parameters

2010-11-03 Thread Lawrence D'Oliveiro
In message <5f6eceec-1eef-4db7-82a6-e5f553349...@k22g2000yqh.googlegroups.com>, Ian wrote: > It seems to me that there is a rather simple case to be made for > allowing mutable default arguments: instances of user-defined classes > are fundamentally mutable. Disallowing mutable default arguments

Re: functions, list, default parameters

2010-11-02 Thread Paul Rudin
Terry Reedy writes: > Suppose I write an nasty C extension that mutates tuples. What then > would be illegal about... Depends on exactly what we mean by legal. If immutability is part of the language spec (rather than an artifact of a particular implementation) then a compiler could assume immut

Re: functions, list, default parameters

2010-11-02 Thread Ian
On Nov 2, 5:59 am, Steven D'Aprano wrote: > Certainly it's the mediocre programmers who seem to be incapable of > understanding that Python has no way of telling whether arbitrary objects > are mutable or not. > > def foo(x, y=list()): >     pass > > Is y a mutabledefaultor not? > > For the benefi

Re: functions, list, default parameters

2010-11-02 Thread Robert Kern
On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote: In message, Robert Kern wrote: On 2010-11-01 22:31 , Lawrence D'Oliveiro wrote: In message<8j1seqfa1...@mid.individual.net>, Gregory Ewing wrote: Steven D'Aprano wrote: And how does Python know whether some arbitrary default object is mutable

Re: functions, list, default parameters

2010-11-02 Thread Terry Reedy
On 11/2/2010 3:12 AM, Lawrence D'Oliveiro wrote: "Immutable objects" are just those without an obvious API for modifying them. After initial creation ;-)/ They are ones with NO legal language constructs for modifying them. Suppose I write an nasty C extension that mutates tuples. What then

Re: functions, list, default parameters

2010-11-02 Thread Steven D'Aprano
On Tue, 02 Nov 2010 00:40:17 -0700, Chris Rebert wrote: > On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano > wrote: >> On Thu, 21 Oct 2010 19:53:53 -0700, John Nagle wrote: This is a common newbie stumbling-block: Don't use lists (or anything mutable) as default argument values >>> >>>

Re: functions, list, default parameters

2010-11-02 Thread Steven D'Aprano
On Tue, 02 Nov 2010 20:12:49 +1300, Lawrence D'Oliveiro wrote about mutable defaults: > Which is what we’re talking about > here: a language construct which is probably one of the top 3 sources of > grief to Python newbies. And not-so-newbies. I call bullshit. Maybe you should spend some time o

Re: functions, list, default parameters

2010-11-02 Thread Steven D'Aprano
On Tue, 02 Nov 2010 22:06:40 +1300, Lawrence D'Oliveiro wrote: > In message , Chris > Rebert wrote: > >> On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano >> wrote: >>> >>> Default mutable arguments have their place >> >> But it's a rather obscure one where it is almost never strictly >> necess

Re: functions, list, default parameters

2010-11-02 Thread Lawrence D'Oliveiro
In message , Chris Rebert wrote: > On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano > wrote: >> >> Default mutable arguments have their place > > But it's a rather obscure one where it is almost never strictly > necessary to venture. Mediocre programmers with a hankering towards cleverness la

Re: functions, list, default parameters

2010-11-02 Thread Chris Rebert
On Fri, Oct 22, 2010 at 12:36 AM, Steven D'Aprano wrote: > On Thu, 21 Oct 2010 19:53:53 -0700, John Nagle wrote: >>> This is a common newbie stumbling-block: Don't use lists (or anything >>> mutable) as default argument values >> >>      That really should be an error. > > No it shouldn't. Punishi

Re: functions, list, default parameters

2010-11-02 Thread Lawrence D'Oliveiro
In message , Robert Kern wrote: > On 2010-11-01 22:31 , Lawrence D'Oliveiro wrote: > >> In message<8j1seqfa1...@mid.individual.net>, Gregory Ewing wrote: >> >>> Steven D'Aprano wrote: >>> And how does Python know whether some arbitrary default object is mutable or not? >>> >>> It doesn'

Re: functions, list, default parameters

2010-11-01 Thread Robert Kern
On 2010-11-01 22:31 , Lawrence D'Oliveiro wrote: In message<8j1seqfa1...@mid.individual.net>, Gregory Ewing wrote: Steven D'Aprano wrote: And how does Python know whether some arbitrary default object is mutable or not? It doesn't, that's the whole point. Of course it knows. It is the one

Re: functions, list, default parameters

2010-11-01 Thread Lawrence D'Oliveiro
In message <8j1seqfa1...@mid.individual.net>, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> And how does Python know whether some arbitrary default object is mutable >> or not? > > It doesn't, that's the whole point. Of course it knows. It is the one defining the concept in the first place

Re: functions, list, default parameters

2010-11-01 Thread Lawrence D'Oliveiro
In message <20101021235138.609fe...@geekmail.invalid>, Andreas Waldenburger wrote: > While not very commonly needed, why should a shared default argument be > forbidden? Because it’s safer to disallow it than to allow it. -- http://mail.python.org/mailman/listinfo/python-list

Re: functions, list, default parameters

2010-10-30 Thread Steven D'Aprano
On Sat, 30 Oct 2010 19:31:53 +1300, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> And how does Python know whether some arbitrary default object is >> mutable or not? > > It doesn't, that's the whole point. I think we're in violent agreement :) -- Steven -- http://mail.python.org/mail

Re: functions, list, default parameters

2010-10-29 Thread Gregory Ewing
Steven D'Aprano wrote: And how does Python know whether some arbitrary default object is mutable or not? It doesn't, that's the whole point. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: functions, list, default parameters

2010-10-29 Thread Dan Stromberg
On Thu, Oct 21, 2010 at 7:53 PM, John Nagle wrote: > On 10/21/2010 2:51 PM, Chris Rebert wrote: > >> On Thu, Oct 21, 2010 at 2:36 PM, Sean Choi wrote: >> >>> I found two similar questions in the mailing list, but I didn't >>> understand >>> >>> the explanations. >>> I ran this code on Ubuntu 10.

Re: functions, list, default parameters

2010-10-29 Thread Steven D'Aprano
On Fri, 29 Oct 2010 21:24:23 +1300, Gregory Ewing wrote: > John Nagle wrote: >> On 10/21/2010 2:51 PM, Chris Rebert wrote: > >>> This is a common newbie stumbling-block: Don't use lists (or anything >>> mutable) as default argument values > >> That really should be an error. > > No, it shou

Re: functions, list, default parameters

2010-10-29 Thread Gregory Ewing
John Nagle wrote: On 10/21/2010 2:51 PM, Chris Rebert wrote: This is a common newbie stumbling-block: Don't use lists (or anything mutable) as default argument values That really should be an error. No, it shouldn't. The criterion isn't whether the object is mutable, but whether you a

Re: functions, list, default parameters

2010-10-22 Thread Dave Angel
On 2:59 PM, Sean Choi wrote: I found two similar questions in the mailing list, but I didn't understand the explanations. I ran this code on Ubuntu 10.04 with Python 2.6.5. Why do the functions g and behave differently? If calls (3) and g(3) both exit their functions in the same state,

Re: functions, list, default parameters

2010-10-22 Thread Steven D'Aprano
On Thu, 21 Oct 2010 19:53:53 -0700, John Nagle wrote: >> This is a common newbie stumbling-block: Don't use lists (or anything >> mutable) as default argument values > > That really should be an error. No it shouldn't. Punishing everybody for a newbie mistake that nobody makes twice would

Re: functions, list, default parameters

2010-10-21 Thread Andreas Waldenburger
On Thu, 21 Oct 2010 19:53:53 -0700 John Nagle wrote: > On 10/21/2010 2:51 PM, Chris Rebert wrote: > > On Thu, Oct 21, 2010 at 2:36 PM, Sean Choi wrote: > >> I found two similar questions in the mailing list, but I didn't > >> understand the explanations. > >> I ran this code on Ubuntu 10.04 with

Re: functions, list, default parameters

2010-10-21 Thread John Nagle
On 10/21/2010 2:51 PM, Chris Rebert wrote: On Thu, Oct 21, 2010 at 2:36 PM, Sean Choi wrote: I found two similar questions in the mailing list, but I didn't understand the explanations. I ran this code on Ubuntu 10.04 with Python 2.6.5. Why do the functions g and behave differently? If cal

Re: functions, list, default parameters

2010-10-21 Thread Chris Rebert
On Thu, Oct 21, 2010 at 2:36 PM, Sean Choi wrote: > I found two similar questions in the mailing list, but I didn't understand > the explanations. > I ran this code on Ubuntu 10.04 with Python 2.6.5. > Why do the functions g and behave differently? If calls (3) and > g(3) both exit their

functions, list, default parameters

2010-10-21 Thread Sean Choi
I found two similar questions in the mailing list, but I didn't understand the explanations. I ran this code on Ubuntu 10.04 with Python 2.6.5. Why do the functions g and behave differently? If calls (3) and g(3) both exit their functions in the same state, why do they not enter in the s