A suggestion
Hannes Hirzel
hirzel at spw.unizh.ch
Tue Mar 12 08:42:25 UTC 2002
On Tue, 12 Mar 2002, Stephan Rudlof wrote:
> 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.
>
>
I consider this to be a useful addition written in a readable style.
Hannes Hirzel
More information about the Squeak-dev
mailing list
|