Re: Default mutable parameters in functions

2014-04-04 Thread Dave Angel
Dennis Lee Bieber Wrote in message: > On Fri, 04 Apr 2014 10:00:25 -0400, random...@fastmail.us declaimed the > following: > >> >>I can't imagine a language that would work that way. For one, it would >>also imply that passing a value would change the default for future >>calls even for non-mutab

Re: Default mutable parameters in functions

2014-04-04 Thread Roy Smith
In article , Dennis Lee Bieber wrote: > On Fri, 04 Apr 2014 10:00:25 -0400, random...@fastmail.us declaimed the > following: > > > > >I can't imagine a language that would work that way. For one, it would > >also imply that passing a value would change the default for future > >calls even for n

Re: Default mutable parameters in functions

2014-04-04 Thread Chris Angelico
On Sat, Apr 5, 2014 at 1:34 AM, Steven D'Aprano wrote: > But it's not hard to get that effect in Python, mutable or immutable > doesn't matter: > > > py> def spam(count, food="spam"): > ... spam.__defaults__ = (food,) > ... return food*count > ... > py> spam(5) > 'spamspamspamspamspam' > p

Re: Default mutable parameters in functions

2014-04-04 Thread Steven D'Aprano
On Fri, 04 Apr 2014 10:00:25 -0400, random832 wrote: > On Thu, Apr 3, 2014, at 20:38, Mark Lawrence wrote: >> I just wish I had a quid for every time somebody expects something out >> of Python, that way I'd have retired years ago. At least here it's not >> accompanied by "as that's how it works

Re: Default mutable parameters in functions

2014-04-04 Thread random832
On Thu, Apr 3, 2014, at 20:38, Mark Lawrence wrote: > I just wish I had a quid for every time somebody expects something out > of Python, that way I'd have retired years ago. At least here it's not > accompanied by "as that's how it works in ". I can't imagine a language that would work that wa

Re: Default mutable parameters in functions

2014-04-03 Thread Mark Lawrence
On 03/04/2014 19:49, fbick...@gmail.com wrote: Hi all, So I was reading about default values for functions and spied this: [snip] I was rather expecting it to start with 4! I just wish I had a quid for every time somebody expects something out of Python, that way I'd have retired years a

Re: Default mutable parameters in functions

2014-04-03 Thread Ethan Furman
On 04/03/2014 11:49 AM, fbick...@gmail.com wrote: I put this into pythontutor.com's code visualization tool (http://goo.gl/XOmMjR) and it makes more sense what's going on. I thought this was interesting; thought I would share. That visualization tool is certainly neat, thanks! -- ~Ethan~ --

Re: Default mutable parameters in functions

2014-04-03 Thread Ian Kelly
On Thu, Apr 3, 2014 at 12:49 PM, wrote: > Now call it with a value: > foo([ 3 ]) > > as you might expect: > It's a parrot, not a cheese: [3] > > But now go back to no parameter in the call: > foo() > foo() > foo() > > It's a parrot, not a cheese: [46] > It's a parrot, not a cheese: [47] > It's a