Re: set variables, in mass
Re: set variables, in mass
- Subject: Re: set variables, in mass
- From: "Adam K. Wuellner" <email@hidden>
- Date: Wed, 1 Dec 2004 11:09:36 -0600
On Nov 30, 2004, at 7:25 PM, halloolli wrote:
set a to 0 -- a now has 0
copy a to b -- b now has 0
is there any difference between set and copy?
Beyond the obvious syntactic difference which reverse the order of the
operands, yes. When you are setting a variable to any of these types
of values:
lists, records, dates, or script objects
then 'set' will create a reference to the original object in the
variable. This is analogous, in my mind, to creating a hard link to an
existing file in the HFS filesystem, if that analogy helps you.
Consider:
set x to {"a", "b", "c"}
set y to x -- y now 'points' to the same list as x
set item 1 of x to "d"
get item 1 of y -- "d"
set x to {"a", "b", "c"}
copy x to y -- y now has a copy of the list in x
set item 1 of x to "d"
get item 1 of y -- "a"
As far as I know (actually, as far as I've been told by Matt Neuberg's
book* :-) these four data types (lists, records, dates, and script
objects) are the only things that reveal the difference between set and
copy. In all other cases, the two operators are interchangeable.
As Emmanuel pointed out, there is a third form of assignment
a returning b
It seems to behave like set:
set x to {"a", "b", "c"}
x returning y
set item 1 of x to "d"
get item 1 of y -- "d"
Yes - I just noticed a note in the book that calls 'returning' and
'set' synonyms.
HTH
Adam
* As if it doesn't get plugged enough, the book is called "AppleScript:
The Definitive Guide" and is published by O'Reilly.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden