Re: My Worrisome Lists :-)
Re: My Worrisome Lists :-)
- Subject: Re: My Worrisome Lists :-)
- From: Paul Berkowitz <email@hidden>
- Date: Mon, 04 Feb 2002 09:53:32 -0800
On 2/4/02 9:27 AM, "Marc K. Myers" <email@hidden> wrote:
>
> Date: Sun, 03 Feb 2002 20:01:57 -0500
>
> Subject: My Worrisome Lists :-)
>
> From: Stephen Swift <email@hidden>
>
> To: AppleScript <email@hidden>
>
>
>
> To sum it up. My problems are:
>
> 1) I can't use strings as records.
>
> 2) I can't find the item # of an item w/out using a repeat loop
>
> 3) I can't find out if an item is contained in a sub-list w/out using a
>
> repeat loop.
>
>
If you're not adverse to using a scripting addition, problems #2 & #3
>
are easily solved using "collect items of" from the Akua Sweets package.
>
It returns a list of the indices of all items in the target list that
>
match a given string. If there are sub-lists it will return the indices
>
of sub-lists with a match on the first item. If the data is going to be
>
somewhere other than the first item of a sub-list there is an optional
>
parameter that allows you to specify which item of a sub-list to test.
>
>
Unfortunately it is case-sensitive, so you'd have to "normalize" your
>
search strings before running the compare if there are case differences.
>
I was a great user of 'collect items' and the other commands in Akua's List
Suite. But in more recent OS 9 releases (maybe 8.6 too, I forget) it seemed
to be faster to use a repeat loop than the osax. More _convenient_ to use
the osax, but usually slower.
Now, in OS X where there's no Akua, I just throw in a short handler an call
that, which is just as convenient as the osax. And fast here, too, at least
until the AS team gives us whose clauses for lists.
to CollectItemIndices(theList, theItem) -- the Item can be string, number or
list
local aListMember, theIndices
set theIndices to {}
repeat with i from 1 to (count theList)
set aListMember to item i of theList
if aListMember = theItem then
set end of theIndices to i
end if
end repeat
return theIndices
end CollectItemIndices
to RemoveListItems(theList, exclItems) -- both lists
local tempList, theItem
set tempList to {}
repeat with i from 1 to (count theList)
set theItem to item i of theList
if {theItem} is not in exclItems then
set end of tempList to theItem
end if
end repeat
return tempList
end RemoveListItems
--
Paul Berkowitz