Richard A. O'Keefe
ok at cs.otago.ac.nz
Mon Mar 11 22:39:33 UTC 2002
Recently, a friend wrote a data mining program in 100 SLOC of Python.
Naturally, I just _had_ to do the same thing in Squeak.
A key step in the algorithm is sorting a collection of (sorted)
sequences of integers. I was using an OrderedCollection of Arrays of
(numbers that happen to be) SmallIntegers. The obvious
doesn't work because you can't use #< between two Arrays.
So I added < <= > >= between:and: to category 'comparing'
and min: max: min:max: to category 'testing' of SequenceableCollection.
The definition of < is
|m n a b|
m := self size.
n := anotherSequence size.
1 to: (m min: n) do: [:i|
a := self at: i.
b := anotherSequence at: i.
a = b ifFalse: [^a < b]].
^m < n
and the other definitions follow naturally from this.
The amount of code required
Before I wrap this up as an [ENH],
(a) is there any reason why this _shouldn't_ be done?
It seems to be useful in Python and Prolog.
(b) is there a better way to do it?
More information about the Squeak-dev