[Python-ideas] A "local" pseudo-function

Soni L. fakedme+py at gmail.com
Sun Apr 29 15:23:02 EDT 2018



On 2018-04-29 04:17 PM, Nikolaus Rath wrote:
> On Apr 27 2018, Tim Peters <tim.peters-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
>> Then `c` is 12, but `a` is still 1 and `b` is still 2.  Same thing in the end:
>>
>> c = local(a=3, b=4, a*b)
> I think this can be done already with slighly different syntax:
>
> c = (lambda a=3, b=4: a*b)()
>
>
> The trailing () is a little ugly, but the semantics are much more
> obvious. So maybe go with a variation that makes function evaluation
> implicit?
>
> c = lambda! a=3, b=4: a*b
>
> (reads terrible, but maybe someone has a better idea).
>
>
>> if local(m = re.match(regexp, line)):
>>      print(m.group(0))
> Of course, that wouldn't (and shouldn't) work anymore. But that's a good
> thing, IMO :-).
>
>
> Best,
> -Nikolaus
>

Has anyone heard of Lua? Lexical scoping? Block scope? (Python doesn't 
have blocks and that sucks?) Etc?


More information about the Python-ideas mailing list