sort question

Jim Ault JimAultWins at yahoo.com
Sat Jun 4 16:37:15 EDT 2005


<answering on top for clarity>
Yes, Wouter, you are right.  Your sort result is true and exactly correct,
given the data source.  I am also on a Mac, but that should make absolutely
no difference.

First four sorted values in the output list are
> 10.101-
> 11.151-
> 4.101-
> 5.101.1-
which a TEXT sort, because there is a trailing space on each of these lines,
which means that this will not be a good number sort.  The answer is to
clean the data or adjust the function to handle characters after the "-"
sign.  (Beware when positive numbers are used and there is no sign, or there
are multiple spaces.)

After that, the sorted values are indeed numeric
from -20.101  ascending to -1.101
Removing all  spaces would give a numeric result using all lines.
Adding ->(replace " " with "" in tSource) should do the trick.

So, all is well and functioning with Rev's sort :-)

Jim Ault
Las Vegas

PS  The reason "10.101- " becomes a text sort is that the parsing function,
as I wrote it, will build the following "- 10.101" rather than "-10.101".
Notice the space after the "-".  (I was not expecting spaces to be there)



On 6/3/05 7:33 PM, "Wouter" <wouter.abraham at scarlet.be> wrote:

> 
> On 03 Jun 2005, at 20:09, Jim Ault wrote:
> 
>> Greetings, jack
> 
> snip
> 
> 
>> on sortFldSource
>>   put fld "source" into tSource  --lines to sort
>>   sort lines of tSource numeric by numberConvert(each)
>>   put tSource into fld "destination"  --output for your review
>> end sortFldSource
>> 
>> function numberConvert pStrToConvert
>>   if pStrToConvert is "" then
>>     return ""
>>   else
>>     set itemdel to  "."
>>     if the last char of pStrToConvert is "-" then
>>       put the last char of pStrToConvert into tSign
>>       delete the last char of pStrToConvert
>>     end if
>>     put item 1 of pStrToConvert into tIntPart
>>     put item 2 of pStrToConvert into tDecPart1
>>     if the number of items in pStrToConvert > 2 then
>>       put item 3 of pStrToConvert into tDecPart2
>>     else
>>       put "" into tDecPart2
>>     end if
>>     put tSign & tIntPart & "." & tDecPart1 & tDecPart2 into tReply
>>     return tReply
>>   end if
>> end numberConvert
>> 
>> Thanks to jeanne a. e. devoto for this (each) form of the "sort
>> lines of"
>> command.
>> 
>> Jim Ault
>> Las Vegas
>> 
>> On 6/3/05 9:45 AM, "revinfo1155 at aol.com" <revinfo1155 at aol.com> wrote:
> 
> Hi Jim,
> 
> I don't know on your computer but on my mac this handler gives the
> following result for Jack's list:
> 
> 10.101-
> 11.151-
> 4.101-
> 5.101.1-
> 20.101-
> 11.101.1-
> 10.501-
> 10.401-
> 10.351-
> 10.301.1-
> 10.201-
> 9.351-
> 9.101.1-
> 8.301-
> 8.101-
> 7.501.1-
> 7.401-
> 7.251-
> 7.201.1-
> 7.151.1-
> 7.101-
> 6.401.1-
> 6.301-
> 6.201.1-
> 6.101.1-
> 5.701-
> 5.651-
> 5.501-
> 5.451-
> 5.401-
> 5.351.1-
> 5.301-
> 5.201-
> 5.151-
> 4.991-
> 3.101-
> 2.301-
> 2.101-
> 1.101-
--snip --
> Greetings,
> Wouter
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list