Re: Bizarre method keyword-arg bug.

2008-08-20 Thread Steven D'Aprano
On Wed, 20 Aug 2008 15:58:44 -0400, Robert Brown wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> On Wed, 20 Aug 2008 13:09:21 -0400, Robert Brown wrote: >> >>> In any case, chances are high that Lisp's way of handling default >>> arguments would have been changed had it been shown to cause

Re: Bizarre method keyword-arg bug.

2008-08-20 Thread Robert Brown
Steven D'Aprano <[EMAIL PROTECTED]> writes: > On Wed, 20 Aug 2008 13:09:21 -0400, Robert Brown wrote: > >> In any case, chances are high that Lisp's way of handling default >> arguments would have been changed had it been shown to cause performance >> problems. > > But nobody is suggesting that it

Re: Bizarre method keyword-arg bug.

2008-08-20 Thread Steven D'Aprano
On Wed, 20 Aug 2008 13:09:21 -0400, Robert Brown wrote: > In any case, chances are high that Lisp's way of handling default > arguments would have been changed had it been shown to cause performance > problems. But nobody is suggesting that it would cause performance problems in *Lisp*. It might

Re: Bizarre method keyword-arg bug.

2008-08-20 Thread Robert Brown
Fredrik Lundh <[EMAIL PROTECTED]> writes: > Robert Brown wrote: >> You may find the above surprising, but Common Lisp users expect the >> default argument expression to be evaluated anew when needed by a >> function call: > > well, I'd say an argument based on "Common Lisp users" is a lot more > du

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Fredrik Lundh
Robert Brown wrote: You may find the above surprising, but Common Lisp users expect the default argument expression to be evaluated anew when need by a function call: I find the Lisp approach more reasonable. Also, an argument based on performance for Python's current behavior seems dubious,

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Fredrik Lundh
Steven D'Aprano wrote: It doesn't help that the solution to get the expected behavior involves adding boiler-plate code all over. Expected by who? Blub programmers. -- http://mail.python.org/mailman/listinfo/python-list

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Fredrik Lundh
Jasper wrote: Having used Python for some 15 years, I'm hardly a neophyte -- it's pure serendipity that this hasn't bitten me before. Using languages and spending time reflecting over how they're put together are two very different things. -- http://mail.python.org/mailman/listinfo/python

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Robert Brown
Steven D'Aprano <[EMAIL PROTECTED]> writes: > On Mon, 18 Aug 2008 03:20:11 -0700, Jasper wrote: > "And no, the alternative /does not/ have an equivalent set of surprises > -- it's not like Python is unique in having default arguments." > > That's simply not true. I would find this behaviour very

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Steven D'Aprano
On Mon, 18 Aug 2008 03:20:11 -0700, Jasper wrote: > It doesn't help that the solution to get the expected behavior involves > adding boiler-plate code all over. Expected by who? Please don't assume that everyone has had their intuition shaped by exposure to the same languages yours has been sha

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Steven D'Aprano
On Mon, 18 Aug 2008 04:07:14 -0700, Paul Boddie wrote: > Ultimately, I suppose one could enforce some kind of least surprising > "best practice" by limiting default parameter values to being literals > of immutable objects or names, as opposed to expressions, thus > eliminating some potential conf

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Paul Boddie
On 18 Aug, 12:20, Jasper <[EMAIL PROTECTED]> wrote: > > Not surprising, as it's fairly non-standard.  I'd even argue that > calling them "default arguments" is a misnomer -- they're more akin to > static variables. Indeed, default parameter values are occasionally suggested for that purpose, altho

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Jasper
On Aug 18, 3:04 am, Paul Boddie <[EMAIL PROTECTED]> wrote: > > Well, in the page of "Python warts" that I compiled when it was > claimed that Python 3000 addresses such issues in Python 2.x, the > "Mutable default arguments" entry lists at least one experienced > Python author who agrees with the i

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Paul Boddie
On 18 Aug, 11:40, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Jasper wrote: > > Uggg!  /That's/ an intuitive side-effect/wart.  :-/ > > it's done that way on purpose, of course, because evaluating a full > closure for each default argument at every call would greatly hurt > performance (and lead to

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Jasper
On Aug 18, 2:40 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Jasper wrote: > > Uggg! /That's/ an intuitive side-effect/wart. :-/ > > it's done that way on purpose, of course, because evaluating a full > closure for each default argument at every call would greatly hurt > performance (and lead t

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Fredrik Lundh
Jasper wrote: Uggg! /That's/ an intuitive side-effect/wart. :-/ it's done that way on purpose, of course, because evaluating a full closure for each default argument at every call would greatly hurt performance (and lead to another set of surprises, of course). please don't label things

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Jasper
On Aug 18, 1:49 am, "Simon Brunning" <[EMAIL PROTECTED]> wrote: > 2008/8/18 Jasper <[EMAIL PROTECTED]>: > > > I'm stumped. I'm calling a method that has keyword args, but not > > setting them, and yet one of them starts off with data?! > >

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Fredrik Lundh
Fredrik Lundh wrote: default argument values are evaluated when the function object is created (by the "def" statement, that is), not when the resulting function is called. if you mutate the default values, the mutations will stick. and yes, workarounds and further details are provided here

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Fredrik Lundh
Jasper wrote: I'm stumped. I'm calling a method that has keyword args, but not setting them, and yet one of them starts off with data?! The class definition begins like so: class BattleIntentionAction( BattleAction ): def __init__( self, factionName, location, tactic='hold', targetFacName

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Diez B. Roggisch
Jasper schrieb: I'm stumped. I'm calling a method that has keyword args, but not setting them, and yet one of them starts off with data?! The class definition begins like so: class BattleIntentionAction( BattleAction ): def __init__( self, factionName, location, tactic='hold', targetFacNam

Re: Bizarre method keyword-arg bug.

2008-08-18 Thread Simon Brunning
2008/8/18 Jasper <[EMAIL PROTECTED]>: > I'm stumped. I'm calling a method that has keyword args, but not > setting them, and yet one of them starts off with data?! -- Cheers, Simon B. [EMAIL PROTECTED] http:/