Quicksort in Squeak (Functional Programming)

Paul Fernhout pdfernhout at kurtz-fernhout.com
Wed Jan 6 03:15:06 UTC 1999


Squeakers -

I was just looking at this web page
http://www.haskell.org/aboutHaskell.html
and could not resists the implied challenge to define quicksort
concisely for Squeak...

SequenceableCollection>>quicksort
	"#(10 1 20 30 5 9) quicksort."
	self size < 1 ifTrue: [^ self species new].
	^ (self allButFirst select: [:x | x < self first]) quicksort , (self
species with: self first) , (self allButFirst select: [:x | x >= self
first]) quicksort

Of course, SortedCollection>>sort:to: in Squeak already implements a
sort in much the same way the C code example on the Haskell page does.

This is not to put down Haskell down though. I'm sure one could come up
with a Haskell example Smalltalk could not do as easily (which in this
case was based in large part on Smalltalk's well thought out class
libraries). 

I think functional programming languages like Haskell (and the somewhat
related idea of "intentional programming") are very useful paradigms and
perhaps more could be done with such ideas in Squeak in the future. The
more programmers can spend time saying what they want to happen (ideally
specifying goals which the system achieves for them), the better their
productivity may be. 

In effect, when we use Squeak to create an application, this is what we
are doing for our end users, since they just want to specify the problem
("format text", "rotate cube", "display this HTML page") without
worrying about how it gets done.

-Paul Fernhout
Kurtz-Fernhout Software 
=========================================================
Developers of custom software and educational simulations
Creators of the GPL Garden with Insight(TM) garden simulator
http://www.kurtz-fernhout.com





More information about the Squeak-dev mailing list