Dave Long writes:
> class fillet:
>       "fillet is like let"
>       def __init__(self, val):
>               self.value = val
>       def __getitem__(self, n):
>               if self.value and n == 0:
>                       return self.value
>               raise IndexError
> import re
> for it in fillet(re.match('-([0-9]+)$','-42')):
>       print it.group(1)
> for it in fillet(re.match('-([0-9]+)$','no match')):
>       print it.group(1)

Nice!  You can actually do even better, because Python 'for' has an
'else' which runs if there's no 'break':

for ii in (0, 1):
    print ii, ":"
    for x in fillet(ii): print x; break
    else: print "no"
    
You still don't get the nice elifs, though.

Paul Graham's Arc binds the result of the conditional in "if" to the
local variable "it".  He says he was inspired by Perl's pronouns.

Chuck Moore is considering having colorForth's "if" not consume the
conditional value.


Reply via email to