I find comprehensions to be especially useful in two situations:
1. Transforming a list using some non-standard function, often with some basic input checking:
[int(x)*2+1 for x in seq if x]
(Here, we're assuming x is a string which can possibly be empty or only blanks)
2. Transforming elements from multiple lists together:
['Iter %d took %0.2f secs' % (i, t) for i, t in zip(iters, times) if t > 1.5]
(Where we want output strings only if some iteration took a long time)
Although I'm not too fluent in lisp, I think the equivalent formulations might be longer (since you'd have to write lambda, map, filter and many parens), and perhaps harder to decipher.
Agreed. This example highlights the great savings of the [... _ ...] syntax in Arc (which I'd imagine is a fairly common use-case, especially for map, filter, etc.).
Although ironically in this case, I'd probably use the following:
1. Transforming a list using some non-standard function, often with some basic input checking:
(Here, we're assuming x is a string which can possibly be empty or only blanks)2. Transforming elements from multiple lists together:
(Where we want output strings only if some iteration took a long time)Although I'm not too fluent in lisp, I think the equivalent formulations might be longer (since you'd have to write lambda, map, filter and many parens), and perhaps harder to decipher.