• 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: Considerable simplification should be possible
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Considerable simplification should be possible


  • Subject: Re: Considerable simplification should be possible
  • From: waynemelrose <email@hidden>
  • Date: Tue, 29 Apr 2014 10:39:44 +1000


On 29 Apr 2014, at 10:29 am, Stan Cleveland <email@hidden> wrote:

On Apr 28, 2014, at 4:04 PM, Shane Stanley wrote:

set volumeChoice to (choose from list namesArray with prompt "Choose a volume to mount.")
…
set volumeChoice to item 1 of volumeChoice

Hi all,

I've always been one for clarity, first, and efficiency, second, in my AS coding. To that end, I'd like to suggest a further simplification of the code that Shane posted a bit ago.

The two lines quoted above can be replaced by this one line:

set {volumeChoice} to (choose from list namesArray with prompt "Choose a volume to mount.")

For each pair of braces added around a variable name when it's defined, one pair is removed from its definition. There's no need to "unbrace" volumeChoice with a separate line of code. 

Here's another silly, but clear, example of this technique:

set nestedList to {{{{"Hello, world"}}}}
set {{{{greeting}}}} to nestedList
return greeting
--> "Hello, world"

Regards,
Stan C.


Hi Stan, 

This will fail if the user selects ‘Cancel’ Which is something that Shane’s code was handling. 

Also, I see your point with your example, but I think you’re still making it a little confusing, I think a clearer sample for a new user would be something like 

set {firstName, lastName} to {"wayne", "melrose"}

return firstName
 _______________________________________________
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: 
 >Re: Considerable simplification should be possible (From: Lists <email@hidden>)
 >Re: Considerable simplification should be possible (From: Shane Stanley <email@hidden>)
 >Re: Considerable simplification should be possible (From: Stan Cleveland <email@hidden>)

  • Prev by Date: Re: Considerable simplification should be possible
  • Next by Date: Re: Considerable simplification should be possible
  • Previous by thread: Re: Considerable simplification should be possible
  • Next by thread: Re: Considerable simplification should be possible
  • Index(es):
    • Date
    • Thread