sort by length of line (Weird)
Richard Gaskin
ambassador at fourthworld.com
Tue Dec 13 12:31:28 EST 2011
Mark Wieder wrote:
> I'm sort of OK with it because there's a simple way to get the desired
> answer. But I filed bug 9910 requesting the simplified syntax with
> "numeric" being optional.
Respectfully, I think it may be asking a bit much of the engine - and
perhaps the scripter - to expect the engine to make that sort of guess
correctly in all cases.
When we write:
sort myList by length(each)
...what we're asking the engine to do is two steps:
1. Obtain a list of integers representing the length of each line
2. Sort that list
While both instructions appear in the same statement, they're pretty
much independent of one another, effectively the same as if they were on
separate lines:
get LineLengths(myList) -- some function that works on the list
sort it
So in effect, request #9910 is asking for the engine to examine the
values of any list passed to the sort command, and if it finds that
they're all integers then sort then numerically rather than alphabetically.
On the one hand I agree this would be convenient, since most of the time
that we do sorts on lists consisting of only integers we're doing so
numerically.
But on the other hand it's quite a departure from the established sort
convention in LiveCode, in which it always sorts alphabetically unless
it's explicitly told to do otherwise.
If this request were implemented as requested, it would introduce a
"sometimes" rule, in which the engine sometimes sorts alphabetically and
sometimes not, and the developer would have to keep track of their data
to reliably know what the engine will choose to do.
Taking the request a step further, we might reasonably expect a list of
dates to be sorted by dateTime, but once again if this were the default
behavior we'd have to monitor our data to know what the engine's default
behavior would be.
At a minimum, it may be useful to have changes in the default sorting
behavior governed by a global property, something like "the smartsort",
which would only introduce this "sometimes" rule once it's set, and
otherwise preserve the requirement for explicit sort typing which has
characterized the language thus far.
--
Richard Gaskin
Fourth World
LiveCode training and consulting: http://www.fourthworld.com
Webzine for LiveCode developers: http://www.LiveCodeJournal.com
LiveCode Journal blog: http://LiveCodejournal.com/blog.irv
More information about the use-livecode
mailing list