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
 
Arnaud Delobelle  
View profile  
 More options May 13 2009, 3:44 pm
From: Arnaud Delobelle <arno...@googlemail.com>
Date: Wed, 13 May 2009 20:44:14 +0100
Local: Wed, May 13 2009 3:44 pm
Subject: Re: [Python-ideas] Default arguments in Python - the return - running out of ideas but...

On 13 May 2009, at 20:18, CTO wrote:

> 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.

>>>> @Runtime
> ... def f(x=a**2+2b+c):
> ...    return x
> ...
>>>> a = 1
>>>> b = 2
>>>> c = 3
>>>> f()
> 8

> This seems much more intuitive and useful to me than adding new
> meanings to yield.

This is not possible.

     def f(x=a**2+2*b+c):
        return x

is compiled to something very much like:

     _tmp = x**2+2*b+c
     def f(x=_tmp):
        return x

So it is impossible to find out what expression yields the default  
value of x by just looking at f.  You have to use lambda or use George  
Sakkis' idea of using strings for defaults and evaluating them at call-
time (but I'm not sure this will work reliably with nested functions).

--
Arnaud

_______________________________________________
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.