My big concern here involves the:
if local(m = re.match(regexp, line)):
print(m.group(0))
example. The entire block needs to be implicitly local for that to work - what happens if I assign a new name in that block? Also, what happens with:
if local(m = re.match(regexp1, line)) or
local(m = re.match(regexp2, line)):
print(m.group(0))
Would the special-casing of local still apply to the block? Or would you need to do:
if local(m = re.match(regexp1, line) or re.match(regexp2, line)):
print(m.group(0))
This might just be lack of coffee and sleep talking, but maybe new "scoping delimiters" could be introduced. Yes - I'm suggesting introducing curly braces for blocks, but with a limited scope (pun intended).
Within a local {} block statements and expressions are evaluated exactly like they currently are, including branching statements, optional semi-colons, etc. The value returned from the block is from an explicit return, or the last evalauted expression.
a = 1
b = 2
c =
local(a=3) * local(b=4)
c = local { a=3 } * local { b=4 }
c =
local(a=3,
b=4,
a*b)
c =
local {
a=3;
b=4;
a*b }
c = local(a=3,
b=local(a=2, a*a), a*b)
a = 3
b = local(a=2, a*a)
r1, r2 = local(D = b**2 - 4*a*c,
sqrtD = math.sqrt(D),
twoa = 2*a,
((-b + sqrtD)/twoa, (-b - sqrtD)/twoa))
D = b**2 - 4*a*c
sqrtD = math.sqrt(D)
twoa = 2*a
return ((-b + sqrtD)/twoa, (-b - sqrtD)/twoa)
}
if local(m = re.match(regexp, line)):
print(m.group(0))
if local { m = re.match(regexp, line) }: print(m.group(0))
And a further implication:
a = lambda a, b: local(c=4, a*b*c)
a = lambda a, b: local {
c = 4
return a * b * c
}
Tim Delaney