• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how to compare two lists without looping? Possible?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to compare two lists without looping? Possible?


  • Subject: Re: how to compare two lists without looping? Possible?
  • From: Stan Cleveland <email@hidden>
  • Date: Thu, 09 Feb 2006 18:37:10 -0800
  • Thread-topic: how to compare two lists without looping? Possible?

On 2/9/06, email@hidden wrote:

> You wouldn't have to do a loop if you have two files to compare.
> Instead of making two list, try making two text files.  One file with
> the numbers you want, the other with the numbers you have (being the
> bigger of the two).

On 2/9/06, email@hidden wrote:

> The only way I can think of requires a loop, though not complex.


How about recursion combined with offset of a string in a string? (Yes, I
know it's silly, but hey...it works.)

set found to {"192.168.1.11", "192.168.1.66"}
set mustHave to {"192.168.1.11", "192.168.1.66", ¬
    "192.168.1.34", "192.168.1.44"}

-- convert lists to return-delimited text
set oldTids to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
-- add null string at end to get needed trailing return
set foundTxt to (found & {""}) as text
set needTxt to (mustHave & {""}) as text
set AppleScript's text item delimiters to oldTids
set missing to {}
set {foundTxt, missing} to checkNext(foundTxt, needTxt, missing)
return missing

on checkNext(foundTxt, needTxt, missing)
    set pos to offset of return in needTxt
    if (text 1 thru pos of needTxt) is not in foundTxt then
        set end of missing to (text 1 thru (pos - 1) of needTxt)
    end if
    try
        set needTxt to text (pos + 1) thru -1 of needTxt
    on error number -1728
        return {foundTxt, missing}
    end try
    set {foundTxt, missing} to checkNext(foundTxt, needTxt, missing)
end checkNext


Stan Cleveland
Color Technology Inc.
Portland, Oregon

"Here the recursion is 'duck typed' as a loop, ala Ruby--sort of."


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: how to compare two lists without looping? Possible?
      • From: demski <email@hidden>
  • Prev by Date: Fwd: Another Shell Script question ftp
  • Next by Date: Re: Font issue in quark
  • Previous by thread: Re: how to compare two lists without looping? possible?
  • Next by thread: Re: how to compare two lists without looping? Possible?
  • Index(es):
    • Date
    • Thread