A suggestion
Stephan Rudlof
sr at evolgo.de
Tue Mar 12 01:52:11 UTC 2002
Richard,
"Richard A. O'Keefe" wrote:
>
> 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
> candidates sort
> 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
>
> < anotherSequence
> |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?
Yes. It is good for solving your problem, but...
> It seems to be useful in Python and Prolog.
... spontaneously I think of one other definition of #< here:
You could interpret these colls as vectors and define #< as comparing their
lengths (in Euclidean space...).
This would lead to other results.
I don't think this is less natural than your suggestion.
> (b) is there a better way to do it?
Currently I don't see any.
Greetings,
Stephan
--
Stephan Rudlof (sr at evolgo.de)
"Genius doesn't work on an assembly line basis.
You can't simply say, 'Today I will be brilliant.'"
-- Kirk, "The Ultimate Computer", stardate 4731.3
More information about the Squeak-dev
mailing list
|