Re: Snippet to remove an item from a list
Re: Snippet to remove an item from a list
- Subject: Re: Snippet to remove an item from a list
- From: Arthur J Knapp <email@hidden>
- Date: Tue, 10 Jul 2001 09:51:42 -0400
>
Subject: Re: Snippet to remove an item from a list
>
Date: Mon, 9 Jul 2001 08:38:04 -0700
>
From: Michelle Steiner <email@hidden>
>
On 7/9/01 7:24 AM, Arthur J Knapp <email@hidden> wrote:
>
> Here is the more traditional AppleScript technique:
>
Alternatively (slightly modifying Arthur's script):
>
>
on DeleteAt(lst, x)
>
tell the lst
>
if (x = 1) then
>
return the rest
>
else if (x = the length) then
>
return items 1 thru -2
>
else
>
return (items 1 thru (x - 1)) & ,
>
(items (x + 1) thru -1)
>
end if
>
end tell
>
end DeleteAt
Allow me to be even more alternative:
on DeleteAt(lst, x)
tell lst to if x = 1 then
rest
else if (x = length) then
items 1 thru -2
else
(items 1 thru (x - 1)) & (items (x + 1) thru -1)
end if
end DeleteAt
Here are some new creations:
on InsertAt(lst, x, val)
tell lst to if x = 1 then
{val} & it
else if x > length then
it & {val}
else
items 1 thru (x - 1) & {val} & items x thru -1
end if
end InsertAt
on IndexOf(lst, itm)
set x to 1
tell no & lst to if {itm} is in it then repeat until item x = itm
set x to x + 1
end repeat
x - 1
end IndexOf
Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden
Hey, check out:
http://www.LateNightSW.com