From: George Sakkis <george.sak...@gmail.com>
Date: Thu, 14 May 2009 00:51:33 -0400
Local: Thurs, May 14 2009 12:51 am
Subject: Re: [Python-ideas] Default arguments in Python - the return - running out of ideas but...
On Wed, May 13, 2009 at 10:41 PM, Bruce Leban <br...@leapyear.org> wrote: Confusing?? It's certainly no more confusing than using *args for one > On Wed, May 13, 2009 at 5:10 PM, George Sakkis <george.sak...@gmail.com> >> On Wed, May 13, 2009 at 7:08 PM, Terry Reedy <tjre...@udel.edu> wrote: >> > Bruce Leban wrote: >> > There is a proposal, which I thought was accepted in principle, to make >> Then how about putting the * before the parameter ? >> def myfunc(a, b, *c = lambda: expression): >> It's currently a syntax error, although the fact that "*arg" and > I think similar syntax should do similar things. If *arg means one thing and thing and **args for something else. >> Subproposal (1): Get rid of the explicit lambda for dynamic arguments. Explicitness is in the eye of the beholder, and also an acquired >> That is, >> def myfunc(a, b, *x=[]): >> would be equivalent to what previous proposals would write as >> def myfunc(a, b, *x=lambda: []): > Explicit is better than implicit. There's a thunk getting created here, taste. @decorator is less explicit than f = decorator(f) and yet it's generally considered a successful addition these days, despite the strong opposition it met initially. >> Subproposal (2): If subproposal (1) is accepted, we could get for free Sure, but I'm not sure what's your point here. The compiler can >> (in terms of syntax at least) dynamic args depending on previous ones. >> That is, >> def myfunc(a, b, *m=(a+b)/2): >> would mean >> def myfunc(a, b, *m = lambda a,b: (a+b)/2): >> with the lambda being passed the values of a and b at runtime. > It's not free and that adds quite a bit of complexity. Note that default generate bytecode to the effect of: def myfunc(a, b, *m = (a+b)/2): Ideally an optimizer would further check whether it's safe to inline > Sure Lisp has let and let* but the proposal here is NOT to provide arbitrary Agreed, the primary target is to fix the common gotcha of mutable > computational ability in the parameter list but to provide a way to have > defaults that are not static. We shouldn't over-engineer things just because > we can. defaults, and I'd rather see this handled than nothing at all. A secondary goal that can be achieved here though is to reduce the overusage of None (or other sentinels for that matter). There are several articles to the effect of "Null considered harmful"; also SQL as well as some statically typed languages provide both nullable and non-nullable types and assume the latter by default. The only useful operation to a sentinel is identity check, so you know that every `x = sentinel` assignment should be followed by one or more `if x is sentinel` checks. Fewer nulls means potentially less conditional logic mental overhead. I'm not claiming we should get rid of None of course; there are legitimate reasons for different behavior under different conditions. Here however we're talking about a very specific pattern: def f(a, b=sentinel): if b is sentinel: b = <expression> It may not seem such a big deal, but then again I don't think it's George You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||