• 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: simple problem?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple problem?


  • Subject: Re: simple problem?
  • From: Paul Scott <email@hidden>
  • Date: Wed, 21 Nov 2007 18:23:07 -0800

Actually, I agree with Skeeve. The difficulty with "as string" is that, while it works for this case, and that's not an accident, it's not really saying what you mean. This leads to conceptual difficulties with how lists work and non-functioning code later on. For instance, say you want to be able to have more than one group in effect. You might find the "with multiple selections allowed" parameter -- and then the "if" tests, as currently written, wouldn't work. You might also note the difficulty with using "display dialog" as your only debugging tool -- because it coerces its argument to text, it can obscure differences in what values are. (This isn't a 'class' mismatch, it's just that the values aren't the same: x is not the same thing as {x}.)

To sum up: saying 'item 1 of (choose from list ...)' means you understand that you're dealing with a list. However, an even better solution would be to use "contains" instead of "is" for the tests: you're then not assuming that your list contains exactly one item.

--Chris Nebel
AppleScript Engineering

Oh my, where do I begin!?

Chris, I agree that using "as string" *may* lead to "conceptual difficulties" with how lists work (for novices) and non-functioning code later on, but I wholeheartedly disagree that it isn't saying what I mean. And *any* solution that works now can lead to non-functioning code later on! -- as we all know.

In fact, I absolutely *did* intend to coerce the list to a string, for the very reasons you state as problematic. Since multiple selections were not allowed, my solution works with the given logic. Later, if mulitple selections are enabled (intentially or inadvertantly) -- with no other code changes -- then neither of your alternate solutions will give correct results. But what I have suggested will -- with the given logic; that is the logic will fall through to the final else with nothing matching. This will produce an obvious error condition that must be investigated. Both your suggestions will effect processing on only one item with no error indicated.

In short, if you change to multiple selections, you'll have to make major changes to the logic anyway, so as to iterate through the selected choices. And if you're making those changes, the question of how to isolate each choice naturally arises, and at that time "as string" (as placed) has to go.

So why not use 'item 1 of' or 'contains' now? Because, as I've stated, with no other changes than enabling multiple selections, the code would appear to work with more than one item selected. A match would always be found and processed. But only a single item. However, the script would immediately fail with 'as string' because it wouldn't match anything. Exactly what I intended. For a single selection with the given logic, I think this is appropriate.

Saying 'item 1 of (choose from list ...)' may mean you understand that you're dealing with a list, but saying 'as string' doesn't mean you don't (and I know you're not saying it does). In any case, a careful analysis of the problem will determine which is the better solution.

Having said all that, I must admit that I was less than helpful by suggesting that simple (correct IMHO) fix with no explanation about coercing from a list to a string. But that's why others chimed in, and rightfully so. The mailing list works!

Paul

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

 _______________________________________________
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

References: 
 >simple problem? (From: Celine Latulipe <email@hidden>)
 >Re: simple problem? (From: Paul Scott <email@hidden>)
 >Re: simple problem? (From: Richard Morton <email@hidden>)
 >Re: simple problem? (From: Richard Morton <email@hidden>)
 >Re: simple problem? (From: Christopher Nebel <email@hidden>)

  • Prev by Date: Shut Down
  • Next by Date: generating scripts
  • Previous by thread: Re: simple problem?
  • Next by thread: Re: simple problem?
  • Index(es):
    • Date
    • Thread