[Python-ideas] A "local" pseudo-function
Ken Hilton
kenlhilton at gmail.com
Sat Apr 28 22:11:38 EDT 2018
> 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
;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180429/b518dc03/attachment-0001.html>
More information about the Python-ideas
mailing list