• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: compare list in list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: show/hide package contents
  • Next by Date: Microsoft Outlook for Exchange Mac Version
  • Previous by thread: Re: compare list in list
  • Next by thread: show/hide package contents
  • Index(es):
    • Date
    • Thread