Re: how to do a proper alphabetical sort?
Re: how to do a proper alphabetical sort?
- Subject: Re: how to do a proper alphabetical sort?
- From: "Nigel Garvey" <email@hidden>
- Date: Sat, 10 Mar 2007 01:55:16 +0000
"Stan Cleveland" wrote on Fri, 09 Mar 2007 16:12:17 -0800:
>Nigel,
>
>Suppose we sort the following list using your nifty mergesort handler:
> {"blah", "BLAH", "Blah", "bLAH"}
>The list is returned unchanged, presumably because every value is equivalent
>when ignoring capitalization. By that logic, ANY arrangement of those four
>strings is to be considered sorted.
>
>My question is whether that's correct. Or should differently-cased strings
>that are otherwise identical have ASCII-like rules applied them. In other
>words, when doing a "proper" alphabetical sort, is the following list (with
>its ASCII-based sorting) "more correct" than the list above?:
> {"BLAH", "Blah", "bLAH", "blah"}
Ah yes. I was forgetting. Patrik B. wanted a case-sensitive sort. In that
case, the call to the handler can simply be enclosed in a 'considering
case' block:
set l to {"blah", "BLAH", "Blah", "bLAH"}
considering case
mergeSort(l, 1, -1)
end considering
l
--> {"BLAH", "Blah", "bLAH", "blah"}
AppleScript compares - and thus sorts - case-insensitively by default, so
those strings are all regarded as equal unless 'considering case' is
specified. I believe one of the virtues claimed for merge sorts is that
they don't change the order of items of equal value, which would explain
- once coincidence had been ruled out - why the order didn't change in
your test.
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden