• 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: Strings as list items don't always compare as strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strings as list items don't always compare as strings


  • Subject: Re: Strings as list items don't always compare as strings
  • From: Jon Pugh <email@hidden>
  • Date: Fri, 22 Mar 2013 22:55:15 -0700

On Mar 22, 2013, at 10:42 PM, Rob Lewis wrote:
> This:
>
> property a_list: {"a"}
> repeat with an_item in a_list
>     display dialog an_item --displays "a" (without quotes)
>     an_item is "a" --FALSE!
>     an_item as text is "a" --TRUE
> end repeat
>
> Why, oh why, does a list element that is, in fact, a string not compare as a string?
> Funny thing is, under some conditions it does!
>
> One of AppleScript's enduring mysteries.
>
> Explanation greatly appreciated.

property a_list : {"a"}
repeat with an_item in a_list
	display dialog an_item --displays "a" (without quotes)
	contents of an_item is "a" --FALSE!
end repeat

In this scenario, the variable of a repeat loop, an_item, is a reference, specifically “item 1 of a_list”.  Realizing this will make your life so much better.  You can get the contents of a reference to do what you expect.

It’s not that mysterious.

Jon


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden


  • Follow-Ups:
    • Re: Strings as list items don't always compare as strings
      • From: Deivy Petrescu <email@hidden>
References: 
 >Strings as list items don't always compare as strings (From: Rob Lewis <email@hidden>)

  • Prev by Date: Strings as list items don't always compare as strings
  • Next by Date: Re: Strings as list items don't always compare as strings
  • Previous by thread: Strings as list items don't always compare as strings
  • Next by thread: Re: Strings as list items don't always compare as strings
  • Index(es):
    • Date
    • Thread