Re: Default Value

2013-06-25 Thread Lefavor, Matthew (GSFC-582.0)[MICROTEL LLC]
> > The Apathetic Approach: > > I could just assume that a programmer is responsible for the > code he writes. If he passes mutables into a function as > default arguments, and

Re: Default Value

2013-06-25 Thread Lefavor, Matthew (GSFC-582.0)[MICROTEL LLC]
On Jun 21, 2013, at 11:17 AM, Rick Johnson wrote: > On Thursday, June 20, 2013 5:28:06 PM UTC-5, Lefavor, Matthew > (GSFC-582.0)[MICROTEL LLC] wrote: >> >> [snip example showing dummy coder doing something dumb] >> >> +1. This is what convinces me that keeping references to >> keyword arguments

Re: Default Value

2013-06-25 Thread Ian Kelly
On Sat, Jun 22, 2013 at 8:40 AM, Antoon Pardon wrote: > Are you two guys now egging on Rick Johnson? No. Rick is incorrigible, and I would have been surprised if he responded to that anyway. -- http://mail.python.org/mailman/listinfo/python-list

Re: [SPAM] Re: Default Value

2013-06-24 Thread MRAB
On 24/06/2013 15:22, Grant Edwards wrote: On 2013-06-22, Ian Kelly wrote: On Fri, Jun 21, 2013 at 7:15 PM, Steven D'Aprano wrote: On Fri, 21 Jun 2013 23:49:51 +0100, MRAB wrote: On 21/06/2013 21:44, Rick Johnson wrote: [...] Which in Python would be the "MutableArgumentWarning". *school-

Re: Default Value

2013-06-24 Thread Grant Edwards
On 2013-06-22, Ian Kelly wrote: > On Fri, Jun 21, 2013 at 7:15 PM, Steven D'Aprano > wrote: >> On Fri, 21 Jun 2013 23:49:51 +0100, MRAB wrote: >> >>> On 21/06/2013 21:44, Rick Johnson wrote: >> [...] Which in Python would be the "MutableArgumentWarning". *school-bell* >>> I not

Re: Default Value

2013-06-22 Thread Rotwang
On 22/06/2013 19:49, Rick Johnson wrote: On Saturday, June 22, 2013 12:19:31 PM UTC-5, Rotwang wrote: On 22/06/2013 02:15, Rick Johnson wrote: IS ALL THIS REGISTERING YET? DO YOU UNDERSTAND? No, I don't. These two special cases are not sufficient for me to determine what semantics you are prop

Re: Default Value

2013-06-22 Thread MRAB
On 22/06/2013 03:32, Rick Johnson wrote: On Friday, June 21, 2013 8:54:50 PM UTC-5, MRAB wrote: On 22/06/2013 00:51, Rick Johnson wrote: > On Friday, June 21, 2013 5:49:51 PM UTC-5, MRAB wrote: > My argument has always been that mutables should not be > passed into subroutines as default argumen

Re: Default Value

2013-06-22 Thread Ian Kelly
On Sat, Jun 22, 2013 at 10:49 AM, Dennis Lee Bieber wrote: > On Fri, 21 Jun 2013 19:27:42 -0600, Ian Kelly > declaimed the following: > >>While we're at it, I would like to petition for a function >>terminates(f, args) that I can use to determine whether a function >>will terminate before I actua

Re: Default Value

2013-06-22 Thread Rick Johnson
On Saturday, June 22, 2013 12:19:31 PM UTC-5, Rotwang wrote: > > On 22/06/2013 02:15, Rick Johnson wrote: > > IS ALL THIS REGISTERING YET? DO YOU UNDERSTAND? > > No, I don't. These two special cases are not sufficient > for me to determine what semantics you are proposing for > the general case.

Re: Default Value

2013-06-22 Thread Rotwang
On 22/06/2013 03:01, I wrote: On 22/06/2013 02:15, Rick Johnson wrote: [...] This is what should happen: py> def foo(arg=[]): ... arg.append(1) ... print(arg) ... py> foo() [1] py> foo() [1] py> foo() [1] Yes, Yes, YES! That is intuiti

Re: Default Value

2013-06-22 Thread rusi
On Saturday, June 22, 2013 8:37:20 PM UTC+5:30, Rick Johnson wrote: > I sorry, but FP is not going to wash our sins clean. In > fact, if taken too seriously, FP leads to preaching > professors, intellectually unstimulated students, and > semesters of wasted time that could have been better spent >

Re: Default Value

2013-06-22 Thread rusi
On Saturday, June 22, 2013 8:37:20 PM UTC+5:30, Rick Johnson wrote: > > So for example, if the use-case contained a statement > > like: In order to safeguard customer-satisfaction, the > > ATM's performance shall not degrade beyond 3 seconds > > response time. > > So now - according to our methodol

Re: Default Value

2013-06-22 Thread Rick Johnson
> See my blog [...] > for a history of wishes akin to yours and lessons not > learnt. In short the problems accruing from unconstrained > imperative programming are severe and the solutions are > hard. In the meanwhile, goals such as your 'keep- > procedures-stateless' can and should certainly be >

Re: Default Value

2013-06-22 Thread Antoon Pardon
Op 22-06-13 03:27, Ian Kelly schreef: On Fri, Jun 21, 2013 at 7:15 PM, Steven D'Aprano wrote: On Fri, 21 Jun 2013 23:49:51 +0100, MRAB wrote: On 21/06/2013 21:44, Rick Johnson wrote: [...] Which in Python would be the "MutableArgumentWarning". *school-bell* I notice that you've omitted

Re: Default Value

2013-06-22 Thread Mark Lawrence
On 22/06/2013 02:31, Steven D'Aprano wrote: On Sat, 22 Jun 2013 05:07:59 +1000, Chris Angelico wrote: Oh! I know. Function argument defaults will now be restricted to int/float/tuple. That would do it, right? Nobody would be bothered by little restrictions like that, would they. Alas, tuples

Re: Default Value

2013-06-21 Thread rusi
On Saturday, June 22, 2013 8:25:15 AM UTC+5:30, Rick Johnson wrote: > On Friday, June 21, 2013 9:32:43 PM UTC-5, rusi wrote: > > So Rick... I agree with you... all these theoreticians > > should be burnt at the stake! > > On a more serious note: many > > people make similar mistakes eg Haskellers

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 9:32:43 PM UTC-5, rusi wrote: > So Rick... I agree with you... all these theoreticians > should be burnt at the stake! On a more serious note: many > people make similar mistakes eg Haskellers who think > Haskell is safe. Safer (than something or other) -- Ok > Safe -- NO

Re: Default Value

2013-06-21 Thread Michael Torrie
On 06/21/2013 07:41 PM, Chris Angelico wrote: >> While we're at it, I would like to petition for a function >> terminates(f, args) that I can use to determine whether a function >> will terminate before I actually call it. > > Nice idea from a theoretical point of view, but practicality beats > pu

Re: Default Value

2013-06-21 Thread rusi
On Saturday, June 22, 2013 7:34:18 AM UTC+5:30, MRAB wrote: > Pure functional languages don't have mutables, or even variables, but > then we're not talking about a pure functional language, we're talking > about Python. In which case neither do mathematicians. Do we rewrite the last 1000 years o

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 8:38:21 PM UTC-5, Ian wrote: > The answer to this conundrum is staring you in the face. Thanks for posting a solution for this. Not sure if i'll ever need it, but nice to know. > Note that the TypeError complains that you passed it an > "unhashable" type, and not that you

Re: Default Value

2013-06-21 Thread rusi
On Saturday, June 22, 2013 6:57:42 AM UTC+5:30, Ian wrote: > While we're at it, I would like to petition for a function > terminates(f, args) that I can use to determine whether a function > will terminate before I actually call it. I was going to say something about this -- viz that in prog. lang

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 8:54:50 PM UTC-5, MRAB wrote: > On 22/06/2013 00:51, Rick Johnson wrote: > > On Friday, June 21, 2013 5:49:51 PM UTC-5, MRAB wrote: > > My argument has always been that mutables should not be > > passed into subroutines as default arguments because bad > > things can happen

Re: Default Value

2013-06-21 Thread Rotwang
On 22/06/2013 03:18, Chris Angelico wrote: On Sat, Jun 22, 2013 at 12:01 PM, Rotwang wrote: class hashablelist(list): ... def __hash__(self): ... return hash(tuple(self)) There's a vulnerability in that definition: a=hashablelist((1,[],3)) a [1, [], 3] {a:1} Traceback (most

Re: Default Value

2013-06-21 Thread Chris Angelico
On Sat, Jun 22, 2013 at 12:01 PM, Rotwang wrote: class hashablelist(list): > ... def __hash__(self): > ... return hash(tuple(self)) There's a vulnerability in that definition: >>> a=hashablelist((1,[],3)) >>> a [1, [], 3] >>> {a:1} Traceback (most recent call last): File "", l

Re: Default Value

2013-06-21 Thread Rotwang
On 22/06/2013 02:15, Rick Johnson wrote: On Friday, June 21, 2013 6:40:51 PM UTC-5, Rotwang wrote: On 21/06/2013 19:26, Rick Johnson wrote: [...] I didn't ask what alternative methods of handling default argument binding exist (I can think of several, but none of them strikes me as preferable to

Re: Default Value

2013-06-21 Thread MRAB
On 22/06/2013 02:40, Chris Angelico wrote: On Sat, Jun 22, 2013 at 11:31 AM, Steven D'Aprano wrote: Thinking about this, I think that the only safe thing to do in Rickython 4000 is to prohibit putting mutable objects inside tuples. Putting a list or a dict inside a tuple is just a bug waiting t

Re: Default Value

2013-06-21 Thread MRAB
On 22/06/2013 00:51, Rick Johnson wrote: On Friday, June 21, 2013 5:49:51 PM UTC-5, MRAB wrote: I notice that you've omitted any mention of how you'd know that the argument was mutable. My argument has always been that mutables should not be passed into subroutines as default arguments because

Re: Default Value

2013-06-21 Thread Ian Kelly
On Fri, Jun 21, 2013 at 7:37 PM, Chris Angelico wrote: class HashableList(list): > def __hash__(self): > return 42 Hey, we both picked exactly the same example! -- http://mail.python.org/mailman/listinfo/python-list

Re: Default Value

2013-06-21 Thread Ian Kelly
On Fri, Jun 21, 2013 at 7:15 PM, Rick Johnson wrote: >> > Let's imagine for a second if Python allowed mutable keys in >> > a dictionary, >> which it does > > Am i just to take your word for this? You cannot provide an > example? Here, allow me to "break the ice": > > # Literal > py> d = {

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 8:31:35 PM UTC-5, Steven D'Aprano wrote: > Tuples have to go into the "Bad List" because, although > they themselves are immutable, their contents may not be. > Imagine the confusion and horror that poor developers will > experience when they do something like this: > > de

Re: Default Value

2013-06-21 Thread Chris Angelico
On Sat, Jun 22, 2013 at 11:27 AM, Ian Kelly wrote: > On Fri, Jun 21, 2013 at 7:15 PM, Steven D'Aprano > wrote: >> On Fri, 21 Jun 2013 23:49:51 +0100, MRAB wrote: >> >>> On 21/06/2013 21:44, Rick Johnson wrote: >> [...] Which in Python would be the "MutableArgumentWarning". *school-

Re: Default Value

2013-06-21 Thread Chris Angelico
On Sat, Jun 22, 2013 at 11:31 AM, Steven D'Aprano wrote: > Thinking about this, I think that the only safe thing to do in Rickython > 4000 is to prohibit putting mutable objects inside tuples. Putting a list > or a dict inside a tuple is just a bug waiting to happen! I think you're onto something

Re: Default Value

2013-06-21 Thread Chris Angelico
On Sat, Jun 22, 2013 at 11:15 AM, Rick Johnson wrote: > # Literal > py> d = {[1]:2} > Traceback (most recent call last): > File "", line 1, in > d = {[1]:2} > TypeError: unhashable type: 'list' > # Symbol > py> lst = [1] > py> d = {lst:2} > Traceback

Re: Default Value

2013-06-21 Thread Steven D'Aprano
On Sat, 22 Jun 2013 05:07:59 +1000, Chris Angelico wrote: > Oh! I know. Function argument defaults will now be restricted to > int/float/tuple. That would do it, right? Nobody would be bothered by > little restrictions like that, would they. Alas, tuples won't do it. Fortunately, you can include

Re: Default Value

2013-06-21 Thread Ian Kelly
On Fri, Jun 21, 2013 at 7:15 PM, Steven D'Aprano wrote: > On Fri, 21 Jun 2013 23:49:51 +0100, MRAB wrote: > >> On 21/06/2013 21:44, Rick Johnson wrote: > [...] >>> Which in Python would be the "MutableArgumentWarning". >>> >>> *school-bell* >>> >> I notice that you've omitted any mention of how yo

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 6:40:51 PM UTC-5, Rotwang wrote: > On 21/06/2013 19:26, Rick Johnson wrote: > [...] > I didn't ask what alternative methods of handling default > argument binding exist (I can think of several, but none > of them strikes me as preferable to how Python currently > does it).

Re: Default Value

2013-06-21 Thread Steven D'Aprano
On Fri, 21 Jun 2013 23:49:51 +0100, MRAB wrote: > On 21/06/2013 21:44, Rick Johnson wrote: [...] >> Which in Python would be the "MutableArgumentWarning". >> >> *school-bell* >> > I notice that you've omitted any mention of how you'd know that the > argument was mutable. That's easy. Just call is

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 5:49:51 PM UTC-5, MRAB wrote: > I notice that you've omitted any mention of how you'd know that the > argument was mutable. My argument has always been that mutables should not be passed into subroutines as default arguments because bad things can happen. And Python's excu

Re: Default Value

2013-06-21 Thread Rotwang
On 21/06/2013 19:26, Rick Johnson wrote: On Friday, June 21, 2013 12:47:56 PM UTC-5, Rotwang wrote: It isn't clear to me from your posts what exactly you're proposing as an alternative to the way Python's default argument binding works. In your version of Python, what exactly would happen when I

Re: Default Value

2013-06-21 Thread MRAB
On 21/06/2013 21:44, Rick Johnson wrote: On Friday, June 21, 2013 2:25:49 PM UTC-5, MRAB wrote: On 21/06/2013 19:26, Rick Johnson wrote: > > The Apathetic Approach: > > I c

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 2:25:49 PM UTC-5, MRAB wrote: > On 21/06/2013 19:26, Rick Johnson wrote: > > > > The Apathetic Approach: > > > > I could just assume that a programmer

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 2:20:22 PM UTC-5, Neil Cerutti wrote: > Rick, it's not a wart, It's a gotcha. The reason it's a > gotcha is this: In order to predict what will happen > correctly, you have to have mastered three separate Python > concepts. > > 1. How name-binding works. > 2. How argument p

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 2:18:27 PM UTC-5, Rick Johnson wrote: > On Friday, June 21, 2013 1:37:13 PM UTC-5, Steven D'Aprano wrote: > > > Okay, you're trolling. Steven, you wouldn't know "trolling" even if you were an honorary salad tosser at a troll face-sitting contest. -- http://mail.python.

Re: Default Value

2013-06-21 Thread MRAB
On 21/06/2013 19:26, Rick Johnson wrote: On Friday, June 21, 2013 12:47:56 PM UTC-5, Rotwang wrote: It isn't clear to me from your posts what exactly you're proposing as an alternative to the way Python's default argument binding works. In your version of Python, what exactly would happen when I

Re: Default Value

2013-06-21 Thread Neil Cerutti
On 2013-06-21, Chris Angelico wrote: > On Sat, Jun 22, 2013 at 4:26 AM, Rick Johnson > wrote: >> I could cast a "virtual net" over my poor lemmings before >> they jump off the cliff by throwing an exception: >> >> Traceback (most recent screw-up last): >>Line BLAH in SCRIPT >> def f(x =

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 1:37:13 PM UTC-5, Steven D'Aprano wrote: > Okay, you're trolling. Time for another month in the kill-file. > *plonk* That's so typical of you. You start losing an argument, and when you have no remaining counter arguments, you resort to name calling. Why am i not surprise

Re: Default Value

2013-06-21 Thread Chris Angelico
On Sat, Jun 22, 2013 at 4:26 AM, Rick Johnson wrote: > I could cast a "virtual net" over my poor lemmings before > they jump off the cliff by throwing an exception: > > Traceback (most recent screw-up last): >Line BLAH in SCRIPT > def f(x = [None, b, [a, [4]]]): > ArgumentError: No mut

Re: Default Value

2013-06-21 Thread Steven D'Aprano
On Fri, 21 Jun 2013 11:26:39 -0700, Rick Johnson wrote: > You know, out of all these post, not one of you guys has presented a > valid use-case that will give validity to the existence of this PyWart LOL. Okay, you're trolling. Time for another month in the kill-file. *plonk* -- Steven -- h

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 12:47:56 PM UTC-5, Rotwang wrote: > It isn't clear to me from your posts what exactly you're > proposing as an alternative to the way Python's default > argument binding works. In your version of Python, what > exactly would happen when I passed a mutable argument as a > de

Re: Default Value

2013-06-21 Thread Rotwang
On 21/06/2013 18:01, Rick Johnson wrote: [stuff] It isn't clear to me from your posts what exactly you're proposing as an alternative to the way Python's default argument binding works. In your version of Python, what exactly would happen when I passed a mutable argument as a default value

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 10:57:17 AM UTC-5, Steven D'Aprano wrote: > On Thu, 20 Jun 2013 11:05:32 -0700, Rick Johnson wrote: > > py> class FuncAdd(object): > > ... def __init__(self, ivalue): > > ... self.ivalue = ivalue > Notice how you are storing state here? I thought you said,

Re: Default Value

2013-06-21 Thread Steven D'Aprano
On Thu, 20 Jun 2013 20:16:19 -0700, Rick Johnson wrote: > On Thursday, June 20, 2013 7:57:28 PM UTC-5, Steven D'Aprano wrote: >> On Thu, 20 Jun 2013 11:05:32 -0700, Rick Johnson wrote: >> They [default argument values] have to be stored *somewhere*, and >> Python chooses to store them as an attri

Re: Default Value

2013-06-21 Thread Steven D'Aprano
On Thu, 20 Jun 2013 11:05:32 -0700, Rick Johnson wrote: > Python functions are objects that take arguments, of which (the > arguments) are then converted to attributes of the function object. > Ah-Ha! Urm, but wait! We already have a method to define Objects. Heck, > I can even create my own calla

Re: Default Value

2013-06-21 Thread Rick Johnson
On Thursday, June 20, 2013 5:28:06 PM UTC-5, Lefavor, Matthew (GSFC-582.0)[MICROTEL LLC] wrote: > > [snip example showing dummy coder doing something dumb] > > +1. This is what convinces me that keeping references to > keyword arguments is actually the right thing to do. > > Perhaps I'm biased b

Re: Default Value

2013-06-21 Thread Rick Johnson
On Friday, June 21, 2013 2:10:49 AM UTC-5, Chris Angelico wrote: > Why should that be? Why is a subroutine not allowed to > retain any state? I refuse to repeat myself for lazy readers! > You're free to write code in a purely functional style if > you like I don't want to write code in a purely

Re: Default Value

2013-06-21 Thread Lefavor, Matthew (GSFC-582.0)[MICROTEL LLC]
Or, in many MANY cases, the choice was the right one, but isn't obvious to everyone. I think it's worth pointing out that changing function defaults to late-binding would merely change the nature of the gotcha, not eliminate it. words = ("one", "two", "red", "blue", "fish") def join_strings(stri

Re: Default Value

2013-06-21 Thread Chris Angelico
On Fri, Jun 21, 2013 at 1:16 PM, Rick Johnson wrote: > On Thursday, June 20, 2013 7:57:28 PM UTC-5, Steven D'Aprano wrote: >> Python functions are >> created *once*, when defined. The cost of building the >> function -- compiling the source code to byte code, >> assembling the pieces into a functi

Re: Default Value

2013-06-20 Thread Rick Johnson
On Thursday, June 20, 2013 7:57:28 PM UTC-5, Steven D'Aprano wrote: > On Thu, 20 Jun 2013 11:05:32 -0700, Rick Johnson wrote: > > Python functions are objects that take arguments, of > > which (the arguments) are then converted to attributes > > of the function object. > Arguments in general are *n

Re: Default Value

2013-06-20 Thread Steven D'Aprano
On Thu, 20 Jun 2013 10:12:01 -0700, rusi wrote: > Python (and all the other 'cool' languages) dont have gotchas because > someone malevolently put them there. > In most cases, the problem is seen too late and the cost of changing > entrenched code too great. > Or the problem is clear, the solution

Re: Default Value

2013-06-20 Thread 88888 Dihedral
rusi於 2013年6月21日星期五UTC+8上午1時12分01秒寫道: > You know Rick, you are good at python, you are better at polemics. > > If only you would cut the crap I would (be able to) agree with you. > > See below > > > > On Jun 20, 7:49 pm, Rick Johnson wrote: > > > On Thursday, June 20, 2013 7:57:06 AM UTC-5,

Re: Default Value

2013-06-20 Thread Tim Chase
On 2013-06-20 21:40, Roy Smith wrote: > In article , > Tim Chase wrote: > > > On 2013-06-21 01:08, Steven D'Aprano wrote: > > > Here's my syntax plucked out of thin air: > > > > > > def func(arg, x=expression, !y=expression): > > > ... > > > > > > where y=expression is late-bound, and the

Re: Default Value

2013-06-20 Thread Roy Smith
In article , Tim Chase wrote: > On 2013-06-21 01:08, Steven D'Aprano wrote: > > Here's my syntax plucked out of thin air: > > > > def func(arg, x=expression, !y=expression): > > ... > > > > where y=expression is late-bound, and the above is compiled to: > > > > def func(arg, x=expression,

Re: Default Value

2013-06-20 Thread Steven D'Aprano
On Thu, 20 Jun 2013 07:49:37 -0700, Rick Johnson wrote: > When the subroutine is completed, all inputs and local variables are > expected to be destroyed. If the programmer wants a return value, he > need simply ask. Data persistence is not a function of subroutines! > Finally, a subroutine should

Re: Default Value

2013-06-20 Thread Tim Chase
On 2013-06-21 01:08, Steven D'Aprano wrote: > Here's my syntax plucked out of thin air: > > def func(arg, x=expression, !y=expression): > ... > > where y=expression is late-bound, and the above is compiled to: > > def func(arg, x=expression, y=None): > if y is None: > y = express

Re: Default Value

2013-06-20 Thread Steven D'Aprano
On Thu, 20 Jun 2013 11:57:34 -0600, Ian Kelly wrote: > Additionally, with late-binding semantics the default values would no > longer be default *values*. They would be initialization code instead, > which sort of flies in the face of the idea that late-binding would > somehow be better for funct

Re: Default Value

2013-06-20 Thread Steven D'Aprano
On Thu, 20 Jun 2013 11:05:32 -0700, Rick Johnson wrote: > On Thursday, June 20, 2013 10:38:34 AM UTC-5, Chris Angelico wrote: >> Function defaults in Python, being implemented as attributes on the >> function object, are very similar in nature to static variables in C. > > Oh wait a minute. i thi

Re: Default Value

2013-06-20 Thread alex23
On 21/06/2013 4:07 AM, Rick Johnson wrote: Okay. So now you are admitting the problem. That is a good start. Thanks for being honest. If you think mutable default arguments is a "problem", then you don't really understand Python. The only "gotcha" here is in people's heads. -- http://mail.py

Re: Default Value

2013-06-20 Thread Roy Smith
In article <51c39b88$0$2$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 20 Jun 2013 09:19:48 -0400, Roy Smith wrote: > > > In article > > <447dd1c6-1bb2-4276-a109-78d7a067b...@d8g2000pbe.googlegroups.com>, > > rusi wrote: > > > >> > > def f(a, L=[]): > >> > >    

Re: Default Value

2013-06-20 Thread Steven D'Aprano
On Thu, 20 Jun 2013 09:19:48 -0400, Roy Smith wrote: > In article > <447dd1c6-1bb2-4276-a109-78d7a067b...@d8g2000pbe.googlegroups.com>, > rusi wrote: > >> > > def f(a, L=[]): >> > >     L.append(a) >> > >     return L > >> Every language has gotchas. This is one of python's. > > One of our pr

Re: Default Value

2013-06-20 Thread rusi
On Jun 20, 10:57 pm, Ian Kelly wrote: > If > the goal is indeed to make the the functions more functional, then the > proper solution would be to keep the binding early but just disallow > mutable defaults altogether -- which is tricky to achieve in Python, > so we simply emulate it with the advic

Re: Default Value

2013-06-20 Thread Rick Johnson
On Thursday, June 20, 2013 12:12:01 PM UTC-5, rusi wrote: > Python (and all the other 'cool' languages) dont have > gotchas because someone malevolently put them there. In > most cases, the problem is seen too late and the cost of > changing entrenched code too great. Okay. So now you are admitt

Re: Default Value

2013-06-20 Thread Rick Johnson
On Thursday, June 20, 2013 10:38:34 AM UTC-5, Chris Angelico wrote: > Function defaults in Python, being implemented as > attributes on the function object, are very similar in > nature to static variables in C. Oh wait a minute. i think it's becoming clear to me now! Python functions are objects

Re: Default Value

2013-06-20 Thread Ian Kelly
On Thu, Jun 20, 2013 at 11:19 AM, Chris Angelico wrote: > On Fri, Jun 21, 2013 at 3:12 AM, rusi wrote: >> Python (and all the other 'cool' languages) dont have gotchas because >> someone malevolently put them there. >> In most cases, the problem is seen too late and the cost of changing >> entren

Re: Default Value

2013-06-20 Thread rusi
On Jun 20, 10:19 pm, Chris Angelico wrote: > On Fri, Jun 21, 2013 at 3:12 AM, rusi wrote: > > Python (and all the other 'cool' languages) dont have gotchas because > > someone malevolently put them there. > > In most cases, the problem is seen too late and the cost of changing > > entrenched code

Re: Default Value

2013-06-20 Thread Chris Angelico
On Fri, Jun 21, 2013 at 3:12 AM, rusi wrote: > Python (and all the other 'cool' languages) dont have gotchas because > someone malevolently put them there. > In most cases, the problem is seen too late and the cost of changing > entrenched code too great. > Or the problem is clear, the solution is

Re: Default Value

2013-06-20 Thread rusi
You know Rick, you are good at python, you are better at polemics. If only you would cut the crap I would (be able to) agree with you. See below On Jun 20, 7:49 pm, Rick Johnson wrote: > On Thursday, June 20, 2013 7:57:06 AM UTC-5, rusi wrote: > > Every language has gotchas. This is one of python

Re: Default Value

2013-06-20 Thread Chris Angelico
On Fri, Jun 21, 2013 at 12:49 AM, Rick Johnson wrote: > When the subroutine is completed, all inputs and local > variables are expected to be destroyed. If the programmer > wants a return value, he need simply ask. Data persistence > is not a function of subroutines! Funny, C violates your descri

Re: Default Value

2013-06-20 Thread Rick Johnson
On Thursday, June 20, 2013 7:57:06 AM UTC-5, rusi wrote: > Every language has gotchas. This is one of python's. So are we purposely injecting illogic into our language just to be part of some "cool crowd" of programming languages with gotchas. "You thought intuitiveness was a virtue? Haha, we go

Re: Default Value

2013-06-20 Thread rusi
On Jun 20, 6:19 pm, Roy Smith wrote: > In article > <447dd1c6-1bb2-4276-a109-78d7a067b...@d8g2000pbe.googlegroups.com>, > >  rusi wrote: > > > > def f(a, L=[]): > > > >     L.append(a) > > > >     return L > > Every language has gotchas. This is one of python's. > > One of our pre-interview scree

Re: Default Value

2013-06-20 Thread Roy Smith
In article <447dd1c6-1bb2-4276-a109-78d7a067b...@d8g2000pbe.googlegroups.com>, rusi wrote: > > > def f(a, L=[]): > > >     L.append(a) > > >     return L > Every language has gotchas. This is one of python's. One of our pre-interview screening questions for Python programmers at Songza is ab

Re: Default Value

2013-06-20 Thread rusi
On Jun 20, 12:38 am, Rick Johnson wrote: > On Wednesday, June 19, 2013 2:17:35 PM UTC-5, Ahmed Abdulshafy wrote: > > I'm reading the Python.org tutorial right now, and I found > > this part rather strange and incomprehensible to me> > > > Important warning: The default value is evaluated only > >

Re: Default Value

2013-06-19 Thread Steven D'Aprano
On Wed, 19 Jun 2013 12:17:35 -0700, Ahmed Abdulshafy wrote: > I'm reading the Python.org tutorial right now, and I found this part > rather strange and incomprehensible to me> > > Important warning: The default value is evaluated only once. This makes > a difference when the default is a mutable

Re: Default Value

2013-06-19 Thread Gary Herron
On 06/19/2013 12:17 PM, Ahmed Abdulshafy wrote: I'm reading the Python.org tutorial right now, and I found this part rather strange and incomprehensible to me> Important warning: The default value is evaluated only once. This makes a difference when the default is a mutable object such as a li

Re: Default Value

2013-06-19 Thread Rick Johnson
On Wednesday, June 19, 2013 2:17:35 PM UTC-5, Ahmed Abdulshafy wrote: > I'm reading the Python.org tutorial right now, and I found > this part rather strange and incomprehensible to me> > > Important warning: The default value is evaluated only > once. This makes a difference when the default is a

Re: Default Value

2013-06-19 Thread Jussi Piitulainen
Ahmed Abdulshafy writes: > I'm reading the Python.org tutorial right now, and I found this part > rather strange and incomprehensible to me > > Important warning: The default value is evaluated only once. This > makes a difference when the default is a mutable object such as a > list, dictionary

Re: Default value for optional parameters unexpected behaviour?

2011-06-26 Thread Corey Richardson
Excerpts from Thomas L. Shinnick's message of Sun Jun 26 14:53:21 -0400 2011: > See reference manual section 7.6 "Function definitions" under the > discussion subtitle "Default parameter values are evaluated when the > function definition is executed. " > > http://docs.python.org/refer

Re: Default value for optional parameters unexpected behaviour?

2011-06-26 Thread Benjamin Kaplan
On Sun, Jun 26, 2011 at 11:28 AM, Marc Aymerich wrote: > Hi, > I'm trying to define a function that has an optional parameter which > should be an empty list whenever it isn't given. However, it takes as > value the same value as the last time the function was executed. What > is the reason of thi

Re: Default value for optional parameters unexpected behaviour?

2011-06-26 Thread Thomas L. Shinnick
At 01:39 PM 6/26/2011, Shashank Singh wrote: On Sun, Jun 26, 2011 at 11:58 PM, Marc Aymerich wrote: > Hi, > I'm trying to define a function that has an optional parameter which > should be an empty list whenever it isn't given. However, it takes as > value the same value as the last time the fun

Re: Default value for optional parameters unexpected behaviour?

2011-06-26 Thread Terry Reedy
On 6/26/2011 2:28 PM, Marc Aymerich wrote: Hi, I'm trying to define a function that has an optional parameter which should be an empty list whenever it isn't given. However, it takes as value the same value as the last time the function was executed. What is the reason of this behaviour? How does

Re: Default value for optional parameters unexpected behaviour?

2011-06-26 Thread Noah Hall
On Sun, Jun 26, 2011 at 7:28 PM, Marc Aymerich wrote: > Hi, > I'm trying to define a function that has an optional parameter which > should be an empty list whenever it isn't given. However, it takes as > value the same value as the last time the function was executed. What > is the reason of this

Re: Default value for optional parameters unexpected behaviour?

2011-06-26 Thread Corey Richardson
Excerpts from Marc Aymerich's message of Sun Jun 26 14:28:30 -0400 2011: > Hi, > I'm trying to define a function that has an optional parameter which > should be an empty list whenever it isn't given. However, it takes as > value the same value as the last time the function was executed. What > is

Re: Default value for optional parameters unexpected behaviour?

2011-06-26 Thread Shashank Singh
On Sun, Jun 26, 2011 at 11:58 PM, Marc Aymerich wrote: > Hi, > I'm trying to define a function that has an optional parameter which > should be an empty list whenever it isn't given. However, it takes as > value the same value as the last time the function was executed. What > is the reason of thi

Re: default value for __init__ doesn't work

2010-09-10 Thread 人言落日是天涯,望极天涯不见家
On Sep 11, 1:55 pm, 人言落日是天涯,望极天涯不见家 wrote: > On Sep 11, 1:14 pm, Benjamin Kaplan wrote: > > > > > On Sat, Sep 11, 2010 at 12:38 AM, 人言落日是天涯,望极天涯不见家 > > wrote: > > > Please look at below code snippet: > > > class test(): > > >    def __init__(self, a, dic={}): > > >        self.a = a > > >      

Re: default value for __init__ doesn't work

2010-09-10 Thread 人言落日是天涯,望极天涯不见家
On Sep 11, 1:14 pm, Benjamin Kaplan wrote: > On Sat, Sep 11, 2010 at 12:38 AM, 人言落日是天涯,望极天涯不见家 > wrote: > > Please look at below code snippet: > > class test(): > >    def __init__(self, a, dic={}): > >        self.a = a > >        self.dic = dic > >        print('__init__ params:',a, dic) > > T

Re: default value for __init__ doesn't work

2010-09-10 Thread Benjamin Kaplan
On Sat, Sep 11, 2010 at 12:38 AM, 人言落日是天涯,望极天涯不见家 wrote: > Please look at below code snippet: > class test(): >    def __init__(self, a, dic={}): >        self.a = a >        self.dic = dic >        print('__init__ params:',a, dic) > This is a pretty popular mistake to make. Default arguments ar

Re: default value in list comprehension

2010-04-19 Thread Bruno Desthuilliers
eb303 a écrit : On Apr 19, 2:20 pm, AlienBaby wrote: Hi, just a quick one, Is it possible to achieve a default value in a list comprehension where the if-clause is false? Ie, something similar to: [ a for a in b if something(a) else 'default' ] the idea being that, rather than skip a value

Re: default value in list comprehension

2010-04-19 Thread AlienBaby
On Apr 19, 1:23 pm, eb303 wrote: > On Apr 19, 2:20 pm, AlienBaby wrote: > > > > > > > Hi, > > > just a quick one, > > > Is it possible to achieve a default value in a list comprehension > > where the if-clause is false? > > > Ie, something similar to: > > > [ a for a in b if something(a) else 'de

Re: default value in list comprehension

2010-04-19 Thread eb303
On Apr 19, 2:20 pm, AlienBaby wrote: > Hi, > > just a quick one, > > Is it possible to achieve a default value in a list comprehension > where the if-clause is false? > > Ie, something similar to: > > [ a for a in b if something(a) else 'default' ] > > the idea being that, rather than skip a value

Re: default value in __init__

2008-10-21 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Oct 14, 1:36 pm, "David C. Ullrich" <[EMAIL PROTECTED]> wrote: > > >[...] > > > In particular default parameters should work the way the user > > expects! The fact that different users will expect different > > things

Re: default value in __init__

2008-10-20 Thread Bruno Desthuilliers
David C. Ullrich a écrit : In article <[EMAIL PROTECTED]>, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: (snip) Well... How to say.. Is there any chance these people will read anything *at all* ? No. That's exactly the point! Yeps. But I don't think we derive the same conclusions from that

  1   2   >