• 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: problem w/ text item delimiters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem w/ text item delimiters


  • Subject: Re: problem w/ text item delimiters
  • From: "J. Stewart" <email@hidden>
  • Date: Wed, 7 Feb 2007 17:27:09 -0500

On 2/7/07 at -0800 Stockly, Ed said this




>using 'contents of myItem' or 'myItem as string' are both acceptable workarounds.


I suggest you rethink this statement. You will cause yourself problems if you get in the habit of using "as string". A case in point, run these with event logging turned on. It looks like these should exit on the first iteration of the loop, 2 of the 3 fail to do so.

--> cut <--  will fail to exit, comparing a reference with an integer
set tList to {1, 2, 3, 4, 5, 6, 7, 8, 9}

repeat with anItem in tList
	if anItem is 1 then exit repeat
	log anItem
end repeat
--> cut <--

--> cut <-- will fail to exit, comparing a string with an integer
set tList to {1, 2, 3, 4, 5, 6, 7, 8, 9}

repeat with anItem in tList
	if (anItem as string) is 1 then exit repeat
	log anItem
end repeat
--> cut <--

--> cut <-- will exit, this is correct behavior
set tList to {1, 2, 3, 4, 5, 6, 7, 8, 9}

repeat with anItem in tList
	if (contents of anItem) is 1 then exit repeat
	log anItem
end repeat
--> cut <--

You would never get caught by this you say! Nawwww of course not, until that is, you get in the habit of using "as string" when what you really want is the unadulterated contents. Not to mention the time wasted to perform the coercion to a string value when you needn't do it and of course there is also the time you will spend debugging a failure.

What you want to do in this type of loop construct is to dereference the list item, not coerce it to something it may or may not be.

JBS
--
If everything seems to be going well, you have obviously overlooked something.
 _______________________________________________
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/mailman//archives/applescript-users

This email sent to email@hidden

References: 
 >Re: problem w/ text item delimiters (From: "Stockly, Ed" <email@hidden>)

  • Prev by Date: Re: Help with writing to a file --- weird characters.
  • Next by Date: applescript saveas menu action
  • Previous by thread: Re: problem w/ text item delimiters
  • Next by thread: Re: problem w/ text item delimiters
  • Index(es):
    • Date
    • Thread