Page 1 of 1

Multiple sorting

Posted: Sun Sep 01, 2013 4:04 am
by dunbarx
This is already an undocumented feature (though it is in the user notes in the dictionary), and harkens back to earliest HC days.

Multiple stable sorting is possible with:

sort container by sortKey1 & sortKey2 & sortKey3... (works for the regular sort command as well)

I wish it were possible to modify the sortKeys independently, so that you could, say:

sort container by sortKey 1 numeric & sortKey 2 text & sortKey 3 dateTime...

How did this get into LC at all, being an undocumented HC gadget? Did it sneak in? At least it should be part of the mainstream dictionary entry.

Craig Newman

Re: Multiple sorting

Posted: Mon Sep 02, 2013 2:24 pm
by Mark
Hi Craig,

If you do the sorts separately, starting with the least dominant sort key, you will get what you want:

Code: Select all

sort lines of myList numeric by item 3 of each // age
sort lines of myList international by item 2 of each // first name
sort lines of myList international by item 1 of each // last name
Kind regards,

Mark

Re: Multiple sorting

Posted: Mon Sep 02, 2013 7:08 pm
by dunbarx
Mark.

Sure. The point of my post was the undocumented feature, not that there is a method of doing such a thing in consecutive lines of code. This is as old as the "sort" command itself, and should be a mainstream variation in the dictionary at least.

Since it is so, I thought it might be nice, and maybe not too onerous, to expand it to include sort modifiers.

Craig

Re: Multiple sorting

Posted: Mon Sep 02, 2013 7:51 pm
by Mark
Hi Craig,

While it would be nice to have those modifiers, I think that's really just what it is: nice. They are not really necessary and they wouldn't me much more efficient as long as the sort routines aren't re-written completely. Now, LiveCode's sort function is pretty fast already and I imagine that it would be pretty hard, and thus time consuming, to write something better. I'm not saying it is impossible, but perhaps it would be better to focus on other features first, such as the new video player. I am also a little concerned that a new sort routine might be incompatible with the current routine, which would be very bad in my opinion.

Kind regards,

Mark