[PD] Vanilla object for "sort"
Chris McCormick
chris at mccormick.cx
Sun May 10 14:09:53 CEST 2015
On 10/05/15 05:54, Miller Puckette wrote:
> Here are three things I could imagine doing for some future release:
>
> a [list sort] built-in that outputs two lists, one the sorted numbers or
> symbols, and the other giving the indices of the items in order
>
> an [array sort] object - I guess that should write its outputs into two
> other arrays, yuck
>
> a [text sort] object that would act like unix "sort": just sort all the lines
> of the text object.
One thing that is useful in some programming languages is the ability to
supply your own comparison algorithm. In Javascript and Python for
example you can pass a function to sort() which gets called for each
combination of items tested and returns -1, 0, or 1, telling sort which
way to swap (or not) each item. Not sure exactly how that would look in
Pd - maybe a crossed-wires patch to some subpatch like the idiomatic
[f]X[+ 1] patch for counters.
Interesting side-note on Javascript sort() - it is a stable sort on most
browsers, but not on Chrome. That little fact ate up two days of my
working life once upon a time! :)
Cheers,
Chris.
--
http://mccormick.cx/
More information about the Pd-list
mailing list