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: Paul Berkowitz <email@hidden>
- Date: Tue, 10 Jul 2001 10:05:12 -0700
On 7/10/01 6:51 AM, "Arthur J Knapp" <email@hidden> wrote:
>
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
>
Aaagh! The ghost of richard23 is come again...
--
Paul Berkowitz