Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Default arguments in Python - the return - running out of ideas but...
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Terry Reedy  
View profile  
 More options May 13 2009, 7:02 pm
From: Terry Reedy <tjre...@udel.edu>
Date: Wed, 13 May 2009 19:02:08 -0400
Local: Wed, May 13 2009 7:02 pm
Subject: Re: [Python-ideas] Default arguments in Python - the return - running out of ideas but...

Steven D'Aprano wrote:
> On Thu, 14 May 2009 05:18:37 am CTO wrote:

>> If you thought not reevaluating function expressions
>> was confusing for newbies, wait until you see what making up a new
>> kind of yield will do for them.

>> Why not just push for some decorators that do this to be included in
>> stdlib? I see the utility, but not the point of adding extra syntax.

> Even if a decorator solution can be made to work, it seems to me that
> the difficulty with a decorator solution is that it is
> all-or-nothing -- you can decorate the entire parameter list, or none
> of the parameters, but not some of the parameters. You can bet that
> people will say they want delayed evaluation of some default arguments
> and compile-time evaluation of others, in the same function definition.

Not all or nothing, and selection is easy.  A decorator could only call
callable objects, and could/should be limited to calling function
objects or even function objects named '<lambda>'.  And if one wanted
the resulting value to such a function, escape the default lambda
expression with lambda.

x=[1,2]
@call_lambdas
def f(a=len(x), lst = lambda:[], func = lambda: lambda x: 2*x):
   # a is int 2, lst is a fresh list, func is a one-parameter function

Terry Jan Reedy

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
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.