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

local { m = re.match(regexp, line) if m: print(m.group(0)) }
Or how about making "local" a pseudo-statement of sorts? local (m=re.match(exp, string)) { if m: print(m.group(0)) } The grammar would be as follows: local_stmt = "local" "(" local_assignments [ "," local_assignments ... ] ")" "{" BLOCK "}" local_assignments = NAME "=" EXPR There would be no question about the scope of things in BLOCK - the variables would disappear after the closing "}". I say "pseudo"-statement because I'm wondering if something like this would be legal: things = list(map(lambda m: local (gp1=m.group(1)) { result = gp1 + ''.join(reversed(gp1)) result += gp1.replace('some', 'thing') return result }, re.finditer(exp, string))) I'm thinking specifically about the "lambda m: local (...) {...}". If that was made legal, it would finally allow for full-fledged anonymous functions. Indeed, the "local" (statement?) itself is actually almost equivalent to defining an anonymous function and executing it immediately, i.e. this: (lambda x=5: x*x)() would be equivalent to this: local (x=5) { return x * x } both evaluating to 25. Just some random thoughts! Sincerely, Ken Hilton ;

I'm pretty sure the debate about braces defining scope in Python has long-since ended... -- Ryan (ライアン) Yoko Shimomura, ryo (supercell/EGOIST), Hiroyuki Sawano >> everyone else https://refi64.com/ On April 28, 2018 9:37:57 PM Ken Hilton <kenlhilton@gmail.com> wrote:
local { m = re.match(regexp, line) if m: print(m.group(0)) }
Or how about making "local" a pseudo-statement of sorts?
local (m=re.match(exp, string)) { if m: print(m.group(0)) }
The grammar would be as follows:
local_stmt = "local" "(" local_assignments [ "," local_assignments ... ] ")" "{" BLOCK "}" local_assignments = NAME "=" EXPR
There would be no question about the scope of things in BLOCK - the variables would disappear after the closing "}". I say "pseudo"-statement because I'm wondering if something like this would be legal:
things = list(map(lambda m: local (gp1=m.group(1)) { result = gp1 + ''.join(reversed(gp1)) result += gp1.replace('some', 'thing') return result }, re.finditer(exp, string)))
I'm thinking specifically about the "lambda m: local (...) {...}". If that was made legal, it would finally allow for full-fledged anonymous functions. Indeed, the "local" (statement?) itself is actually almost equivalent to defining an anonymous function and executing it immediately, i.e. this:
(lambda x=5: x*x)()
would be equivalent to this:
local (x=5) { return x * x }
both evaluating to 25.
Just some random thoughts!
Sincerely, Ken Hilton ;
---------- _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
participants (2)
-
Ken Hilton
-
Ryan Gonzalez