Re: compare list in list
Re: compare list in list
- Subject: Re: compare list in list
- From: Helmut Fuchs <email@hidden>
- Date: Thu, 23 Aug 2001 16:23:18 +0200
At 20:44 Uhr +0800 23.08.2001, Bill wrote:
Suppose there are two lists, how to compare them correctly?
set patList to {{"a", "b"}, {"c", "d"}}
set xx to {"a", "b"}
xx = item 1 of patList
==> true
xx is in patList
==> false
Any idea about the result?
As far as I understand the 'is in' operator, it doesn't really
compare whether an object is contained in another one - it actually
checks whether one object is a subset of another one. If they're not
the same class, then the first item is coerced to match.
So if you write:
"a" is in {"a", "b"}
then it is really executed as:
{"a"} is in {"a", "b"}
because "a" is automatically coerced to a single item list.
In your example xx already IS a list - therefore it isn't coerced,
resulting in the 'is in' operator returning false. Which is correct,
as "a" and "b" don't really occur in patList...
Now if you want to check if an object of any type is contained in a
list, you should put it in curly braces yourself, thereby avoiding
the confusing automatic coercions (which is a good idea anyway).
So:
{xx} is in patList
will return what you expect.
HTH,
Helmut