Multiple sorting

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

Post Reply
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Multiple sorting

Post by dunbarx » Sun Sep 01, 2013 4:04 am

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Multiple sorting

Post by Mark » Mon Sep 02, 2013 2:24 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Multiple sorting

Post by dunbarx » Mon Sep 02, 2013 7:08 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Multiple sorting

Post by Mark » Mon Sep 02, 2013 7:51 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply