• 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: Trimming down a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trimming down a list


  • Subject: Re: Trimming down a list
  • From: Arthur J Knapp <email@hidden>
  • Date: Thu, 11 Apr 2002 11:39:47 -0400

> Date: Thu, 11 Apr 2002 10:53:37 +0100
> Subject: Re: Trimming down a list
> From: Steve Thompson <email@hidden>

> The RemovDuplicates Routine (posted at the end of this message) now works
> but I still think it's a bug. Or a misunderstanding on my part...

I'm afraid it is a misunderstanding.

> set thisItem to item i of RemoveDups's listRef
>
> ...returns thisItem as {"an item"} but :

> set thisItem to item i of RemoveDups's listRef as text
>
> ...return thisItem as "an item".

When the AppleScript development team went to create the "contains"
operator for lists, they appearently wanted to ensure that in addition
to testing for a single item in a list, they also wanted to be able to
test for a range in a list, ie:

{ "a", "b", "c", "d" } contains { "b", "c" } --> true

Many people are not aware of this functionality, however, and of
how it affects lists of sublists. Because the syntax of testing
for a "range" of items requires the items to be contained in a list,
the "correct" syntax of the contains operator is something like this:

searchList contains { findItem, findItem, etc... }

which means that the most "correct" syntax for doing a "contains"
for a single item is this:

searchList contains { findItem }

For better or worse, AppleScript is a very flexable and forgiving
language, and one of the central features of AS's datatypes is the
fact that simple values are implicitly coerced to single-item-lists
where approprite. This means that when we type this:

{ "a", "b", "c" } contains "b"

AppleScript works behind the scenes to change it to this:

{ "a", "b", "c" } contains { "b" } --> hidden coercion, true, "b" = "b"


Now we need to consider the situation of sublists.


{ {"a"}, {"b"}, {"c"} } contains "b" --> secrectly coerced to:
{ {"a"}, {"b"}, {"c"} } contains { "b" } --> false, "b" is not {"b"}

{ {"a"}, {"b"}, {"c"} } contains { "b" } --> false, no coercion

{ {"a"}, {"b"}, {"c"} } contains { {"b"} } --> true

Again, this is to allow for "range" searches:

{ {"a"}, {"b"}, {"c"} } contains { {"b"}, {"c"} } --> true


I may not have explained this very well, which is why I suggest Bill
Cheeseman's excellent article:

<http://www.AppleScriptSourcebook.com/tips/gotchas/listoflists.html>



{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://www.natural-innovations.com/as/>
on error number -128
end try
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: ACGI & OSX - pages greater then 32k???
  • Next by Date: Re: Trimming down a list
  • Previous by thread: Re: Trimming down a list
  • Next by thread: Re: Trimming down a list
  • Index(es):
    • Date
    • Thread