• 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: when to use "copy" vs "set" [was Re: Manipulating text]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: when to use "copy" vs "set" [was Re: Manipulating text]


  • Subject: Re: when to use "copy" vs "set" [was Re: Manipulating text]
  • From: has <email@hidden>
  • Date: Sat, 26 Sep 2009 17:10:40 +0100

Jon Pugh wrote:

>In other words, when do you use "copy" and when "set"

It'a not painfully obvious, in fact it's downright obtuse and has confused people since the dawn of AppleScript.

The flaw in the design of AS's 'copy' command is that it muddles two completely unrelated actions - assignment and cloning - that should have been addressed separately. This just makes it harder for users to understand what it's doing, and why. The correct approach would be to use 'set' for _all_ assignments, and provide a separate 'a copy of' operator for cloning AS objects, e.g.:


	set new_list to a copy of old_list

The rest is just a matter of teaching users the difference between mutable and immutable objects. Which shouldn't be all that difficult, since AS users are already well used to dealing with mutable objects whenever they script applications. Unfortunately, the old ASLG rather went off the rails on that topic, with a bunch of vague waffle about 'data sharing', which really didn't help either.

I suppose there's also the question of how you explain variables, which in AppleScript are simply labels that you attach to in-memory objects so that you can identify those objects again later. Though I will admit to using the more common (if less accurate) 'a variable is a container you put objects in' metaphor myself when explaining this stuff to novices. I've never been quite sure what the best balance between correctness, ease of understanding, and common public usage is on this one.

Ah well; who ever said designing a language was easy...?

Regards,

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

_______________________________________________
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
  • Prev by Date: Re: Manipulating text
  • Next by Date: Re: when to use "copy" vs "set" [was Re: Manipulating text]
  • Previous by thread: [ANN] AppleScriptObjC sample project
  • Next by thread: Re: when to use "copy" vs "set" [was Re: Manipulating text]
  • Index(es):
    • Date
    • Thread