Why is Python popular, while Lisp and Scheme aren't?
Alex Martelli
aleax at aleax.it
Wed Nov 13 06:19:39 EST 2002
Martin Maney wrote:
...
> Think about the straightforward implementation of this in legal Python
> with less undersized indentation than I used before:
[KNode doesn't display your tabs in this reply, so I don't know if they
remained or not -- you can use spaces if you want to avoid such issues).
> for l in lines:
> m = re1.match(l)
> if m:
> ... process type 1
> else:
> m = re2.match(l)
> if m:
> ... process type 2
> else:
> m = re3.match(l)
> if m:
> ... process type 3
Flat is better than nested:
for l in lines:
m = re1.match(1)
if m:
...process type 1...
continue
m = re2.match(1)
if m:
...process type 2...
continue
m = re3.match(1)
if m:
...process type 3...
continue
or probably better, putting the "processtype" into functions:
for l in lines:
for are, processtype in zip((re1,re2,re3),(pt1, pt2, ptr)):
m = are.match(l)
if m:
processtype(m)
break
else:
nomatchfor(l)
exhibiting even better the commonality of structure (IMHO).
I've found myself wishing for "set-and-test" basically in ONE
kind of situation: when I was transcribing algorithms coded in
languages that used that form, such as C. In such cases, of
course, it's trivially easy to build and use set-and-test, see:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66061
Alex
More information about the Python-list
mailing list