Sort of a problem

Jerry Jensen jhj at jhj.com
Fri May 11 01:13:15 EDT 2012


Yeah, but it fails if a street is named "SEW Rd" 8)

A better line would be:
If word 1 of pName is among the words of "N S E W" then

On May 10, 2012, at 9:25 PM, stephen barncard wrote:

> that's the one!
> 
> On Thu, May 10, 2012 at 9:23 PM, Jerry Jensen <jhj at jhj.com> wrote:
> 
>> This seems to do the job. No polish, but you'll get the idea.
>> .Jerry
>> 
>> Aw, crap, forgot about no attachments. Here's the code:
>> 
>> ------------------------------------------------
>> 
>> on mouseUp
>>  local tList
>>  put fld "Streets" into tList
>>  sort lines of tList by pickStreet(each)
>>  put tList into fld "Streets"
>> end mouseUp
>> 
>> function pickStreet pName
>>  if word 1 of pName is in "NSEW" then
>>     return word 2 to -1 of pName
>>  else
>>     return pName
>>  end if
>> end pickStreet
>> 
>> -----------------------------------------------------
>> 
>> On May 10, 2012, at 8:46 PM, Jim Hurley wrote:
>> 
>>> I have a list of streets:
>>> 
>>> Main St
>>> Oak Ave
>>> N Auburn
>>> Kimberly Ct
>>> S Rector Rd
>>> Maple Ave
>>> W Pine St
>>> Fairmont Ave
>>> 
>>> I want to sort them, but ignoring the compass prefix (N E S W) to give:
>>> 
>>> N Auburn
>>> Fairmont Ave
>>> Kimberly Ct
>>> Main St
>>> Maple Ave
>>> Oak Ave
>>> W Pine St
>>> S Rector Rd
>>> 
>>> The best I have come up with is performing a bubble sort where I have
>> control of the first word.
>>> 
>>> That script is below. This works well enough for short lists, but not
>> for longer lists.
>>> It might be possible to speed it up with arrays, but that is not what
>> I'm after right now.
>>> I have seen some amazing things done with custom sorts in Live Code. I
>> confess, I never understood them.
>>> 
>>> Is there a custom sort available in Live Code to do this kind of sort?
>>> 
>>> Thanks,
>>> JIm Hurley
>>> 
>>> Here is the bubble sort:
>>> 
>>> on mouseUp
>>> put field 1 into tList
>>> put "N E S W" into tWordsToIgnore
>>> put the number of lines in tList into n
>>> repeat
>>>    put true into noChange
>>>    repeat with i = 1 to n-1
>>>       put theFirstWord(line i of tList, tWordsToIgnore) into tFirst
>>>       put  theFirstWord(line i + 1 of tList, tWordsToIgnore) into
>> tSecond
>>> --Reverse sequencial pairs if out of order.
>>>       if tFirst > tSecond then
>>>          put line i  of tList into temp
>>>          put line i + 1 of tList into line i of tList
>>>          put temp into line i + 1 of tList
>>>          put false into  noChange
>>>       end if
>>>    end repeat
>>>    if the shiftKey is down then exit to top --Just in case
>>>    if  noChange then exit repeat ---Keep it up until no change.
>>> end repeat
>>> put tList into field 2
>>> end mouseUp
>>> 
>>> function theFirstWord temp, tIgnoreWords
>>> put word 1 of temp into tFIrstWord
>>> if tFirstWord is among the words of tIgnoreWords then
>>>    return word 2 of temp
>>> else
>>>    return word 1 of temp
>>> end if
>>> end theFirstWord
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
> 
> 
> 
> -- 
> 
> 
> 
> Stephen Barncard
> San Francisco Ca. USA
> 
> more about sqb  <http://www.google.com/profiles/sbarncar>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list