# Two new keywords -- "doing" introduces a single unnamed block
# as a parameter to a function after the normal parameters.
# "where" can be used multiple times to introduce unlimited
# blocks via named parameters.
# scoped file operations with a hypothetical error handler
open("somefile", "r") doing (fd):
print fd.read()
where error(e):
print e
# sorting
a = [2, 1, 4, 3]
a.sort() doing (a, b):
return cmp(b, a)
# let's write our own syntax for try/finally!
def attempt(block, no_matter_what=None):
try:
block()
finally:
if no_matter_what: no_matter_what()
# and use that:
attempt() doing:
1 + hello
where no_matter_what():
print "I always get printed"
# here's a crazy idea for dict iteration connected to generators
somedict.iteritems() doing (k, v):
if v:
print k, "has a value"