Re: Index of Handler
Re: Index of Handler
- Subject: Re: Index of Handler
- From: Nigel Garvey <email@hidden>
- Date: Thu, 12 Jul 2001 23:39:48 +0100
List Guy wrote on Wed, 11 Jul 2001 10:25:59 -0700:
>
I suppose that
>
>
on IndexOf(lst, itm)
>
set x to 1
>
tell missing value & lst
>
if {itm} is in it then
>
repeat until item x = itm
>
set x to x + 1
>
end repeat
>
end if
>
end tell
>
return x - 1
>
end IndexOf
>
>
might be clearer because it uses the "missing value" constant, except that
>
soemone might query the list to see if it contains a missing value.
I don't think clarity was the intention in Arthur's script. :-) You could
use '{a reference to ArthurJKnapp}' instead of 'no' or 'missing value'.
It would fail under exactly the same circumstances, but the circumstances
would be less likely to occur. ;-) (For this usage, it doesn't matter
whether or not ArthurJKnapp actually exists.) ;-D
The real problem with Arthur's method is 'x', of course. The process
would be more bullet-proof (and more opaque) like this:
on IndexOf(lst, itm)
set x to 0
tell no & lst to if {itm} is in it then repeat until item (x + 1) =
itm
set x to x + 1
end repeat
x
end IndexOf
... or even something sensible.
NG