List Comprehensions Enhancement
William Tanksley
wtanksle at dolphin.openprojects.net
Tue Sep 14 17:22:56 EDT 1999
On Mon, 13 Sep 1999 22:37:44 -0400, Tim Peters wrote:
>[William Tanksley, comes to the right conclusion]
>> I actually liked the verbosity a lot. I thought it was extremely cool;
>> I'd like to see this in Python, although I suspect it won't make it (it's
>> a little too much like a functional language).
>This was debated at extraordinary length and in extraordinary detail last
>year (or last decade, or some time span long enough ago that I can't
>remember quite when -- maybe last week). Guido was kindly disposed toward
>it, and for the same reason Haskell fans can never go back to Scheme <wink>:
>it can replace almost all common uses of map and filter with much nicer
>syntax; and, in Python's case, can be implemented much more efficiently than
>map/filter are implemented today, via generating inline nested loops.
I can understand the possibility of greater efficiency (it's conceivable
that we'd be able to use C to speed it up in some cases); it's also very
cool that it's available _now_.
>So, now that Greg has stopped harassing Guido in his sig <wink>, it stands a
>better chance than you may think.
I didn't notice Greg doing that. How DOES one harass Guido, anyhow? I
can't think of anything to say about him that isn't a compliment -- "Guido
is such an absolute dictator!" "Guido never listens to my suggestions!"
and so on.
>>> Also, I think there should be a clear separator between the
>>> generators/predicates in your syntax too:
>>> print [(i,s) for i in nums, for s in strs]
>>> or similar.
>> I agree -- my initial reaction was to put 'and' as the seperator. Amazing
>> how great minds think alike :).
>A good way to kill it would be to reopen debate about the syntax <0.9
>wink -- but finding a thoroughly backward-compatible and unambiguous
>spelling isn't easy, and off-the-cuff "gosh, I like the way *this* looks
>better" isn't going to succeed>.
That's true. It's also true that my 'and' suggestion won't work -- it
causes ambiguity:
[(i,s) for i in pairs if i[0] != 3 and i[1] != 4 and for s in strings]
Comma looks fine; let's see...
[(i,s) for i in pairs if i != (3,4), for s in strings]
I don't see any ambiguity. OTOH, there's no ambiguity with no
punctuation, either. I'll be glad to see it with anything except
nonexistance.
>>> Nice thing, though :-)
>> Oh, amazingly. Thanks, Greg. On a scale of one to ten I'd give it a tim.
>Oh, it's not *that* good <wink>.
As Quayle once might have said, "I stand by all the misstatements I may,
or may not, have made."
>but-it-is-more-pythonic-than-python-ly y'rs - tim
--
-William "Billy" Tanksley
More information about the Python-list
mailing list