I can't believe this hasn't come up here before, but it's true. Inspired by http://blog.thezerobit.com/2012/09/01/beautiful-quicksort-in-common-lisp.html: (def qsort(l)
(iflet (p . xs) l
(join (qsort:keep [< _ p] xs) list.p (qsort:keep [>= _ p] xs))))
That compares pretty well with haskell: qsort (p:xs) = qsort [x | x<-xs, x<p] ++ [p] ++ qsort [x | x<-xs, x>=p]
I actually find keep with the anonymous arg more readable than the list comprehensions.Is there some way to get haskell's implicit handling of empty lists? I spent some time trying to build qsort using anarki's partition. No luck. |