Thursday, April 25, 2002


I've finally started some serious ccx-ifying radio. apparently today my themes are dominated by thoughts of David Carson.
7:39:11 PM  blips[]    
I'll admit it
Ken Seehof says: Well, come to think of it, I can't think of a really good use for generator comprehensions, but you have to admit the idea is cute.
5:49:11 PM  blips[]    
Luscious Python FP!
Alright. Here's the Haskell Quicksorter done in quicksorting across the universe as a Python one liner:

qsort = lambda x: x != [] and (qsort([ lt for lt in x[1:] if lt < x[0] ]) + [x[0]] + qsort([ gte for gte in x[1:] if gte >= x[0] ])) or x

In formatted mode:

qsort = lambda x: x != [] and 
           (qsort([ lt for lt in x[1:] if lt < x[0] ]) + 
            [x[0]] + 
            qsort([ gte for gte in x[1:] if gte >= x[0] ])
           ) or x

4:26:49 PM  blips[]    
Compound Document Framework development for Zope, notes
Outline of SCS, a compound document framework for Zope.
1:45:29 PM  blips[]    
quicksorting across the universe
Speaking of Haskell, I once was able to turn the following Haskell example of a Quicksort (not an efficient Quicksort, just one showing Haskell's list comprehensions power) into a one line Python example, combining lambdas, list comprehensions, and good old binary logic.

qsort []     = []
qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
                 where
                   elts_lt_x   = [y | y <- xs, y < x]
                   elts_greq_x = [y | y <- xs, y >= x]

I found a Python version at ActiveState's ASPN, but my version is much more fascinating.

I think it might have gotten lost in the move... I'll try to recreate it tonight.
12:13:50 PM  blips[]    

Generator Comprehensions
It's a shame that the Python PEP 289, Generator Comprehensions, has been rejected. I don't know why this idea appeals so much to me in the first place. Maybe it's a syntax thing. I love Python's functional programming side. I love List Comprehensions. I like generators. Why not put them together? Guido is apparently wary of turning Python into more of a functional language. A nice thing about FP in Python, so far, is that it's had decent support for FP constructs that don't have to be used if one doesn't wish to. I like that Python is so general purpose, but can offer many features found in more obscure and targeted languages like Haskell.
11:48:53 AM  blips[]