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
 
Jeremy Banks  
View profile  
 More options May 13 2009, 10:52 am
From: Jeremy Banks <jer...@jeremybanks.ca>
Date: Wed, 13 May 2009 11:52:57 -0300
Local: Wed, May 13 2009 10:52 am
Subject: Re: [Python-ideas] Default arguments in Python - the return - running out of ideas but...
To someone who's a novice to this, could someone explain to me why it
has to be an existing keyword at all? Since not identifiers are valid
in that context anyway, why couldn't it be a new keyword that can
still be used as an identifier in valid contexts? For example (not
that I advocate this choice of keyword at all):

    def foo(bar reinitialize_default []): # <-- it's a keyword here
        reinitialize_default = "It's an identifier here!"

That would be a syntax error now and if it were defined as a keyword
only in that context it wouldn't introduce backwards compatibility
problems and wouldn't force us to reuse an existing keyword in a
context that may be a bit of a stretch.

Is there a reason that this wouldn't be a viable approach?

On 2009-05-13, MRAB <goo...@mrabarnett.plus.com> wrote:

> Jacob Holm wrote:
>> Pascal Chambon wrote:
>>> One last idea I might have : what about something like

>>> *    def myfunc(a, b, c = yield []):
>>>               pass*

>>> [...], but there is no interpretation conflict for the parser, and we
>>> might quickly get used to it

>> I am surprised that there is no conflict, but it looks like you are
>> technically right.  The parentheses around the yield expression are
>> required in the following (valid) code:

>>  >>> def gen():
>> ...     def func(arg=(yield 'starting')):
>> ...         return arg
>> ...     yield func
>> ...
>>  >>> g = gen()
>>  >>> g.next()
>> 'starting'
>>  >>> f = g.send(42)
>>  >>> f()
>> 42

>> I would hate to see the meaning of the above change depending on whether
>> the parentheses around the yield expression were there or not, so -1 on
>> using "yield" for this.

>> I'm +0 on the general idea of adding a keyword for delayed evaluation of
>> default argument expressions.

> There's the suggestion that Carl Johnson gave:

>      def myfunc(a, b, c else []):
>          pass

> or there's:

>      def myfunc(a, b, c def []):
>          pass

> where 'def' stands for 'default' (or "defaults to").
> _______________________________________________
> Python-ideas mailing list
> Python-id...@python.org
> http://mail.python.org/mailman/listinfo/python-ideas

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