[Python-ideas] Tweaking closures and lexical scoping to include the function being defined

Steven D'Aprano steve at pearwood.info
Sun Oct 2 16:30:29 CEST 2011


Carl Matthew Johnson wrote:
> On Oct 1, 2011, at 8:29 PM, Ron Adam wrote:
>> How about a name space literal? ie.. a dictionary.
>>
>>    def global_counter(x) {n:0, lock=lock}:
>>        with lock:
>>            n += 1
>>            yield n
> 
> Yeah, but it would break this existing code:
> 
> from __future__ import braces


Is that an attempt to be funny? Because braces are already used for 
dictionary and set literals. The __future__ braces refers to braces as 
BEGIN ... END delimiters of code blocks, not any use of braces at all.


While we're throwing around colours for the bike-shed, the colour which 
seems to look best to me is:


def global_counter(x, [n=0, lock=lock]):  # inside the parameter list
     ...

rather than

def global_counter(x) [n=0, lock=lock]:  # outside the parameter list
     ...


but Ron's suggestion that we use dictionary syntax does seem intriguing.



-- 
Steven



More information about the Python-ideas mailing list