Re: List Question: Can someone explain this to me?
Re: List Question: Can someone explain this to me?
- Subject: Re: List Question: Can someone explain this to me?
- From: has <email@hidden>
- Date: Fri, 14 Jun 2002 01:27:36 +0100
steve wrote:
>
For some reason that has been driving me mad all day, this change is also
>
reflected in the ProductCode list.
Everybody gets caught by this one sooner or later. Me? I spent _three_ days
hard up against deadlines trying to track the problem when it bit me, so
consider yourself lucky by comparison. :)
See Data Sharing on p206-7 of ASLG. [1]
HTH
has
[1] BTW, while I'm not entirely sure, I do have a strong feeling the ASLG
explanation is really half-truth, half-fib. AFAIK, data is never copied in
AS unless explicitly instructed, thus 'set n to m' will mean a single
object is shared between both n and m regardless of its type.
What really matters is whether the object in question is mutable or not;
i.e. whether or not you can modify its contents. Simple data types such as
booleans, numbers and strings are immutable; you cannot change their
content. For example, you cannot do:
set s to "fool"
set item 3 of s to "a"
s --> "foal"
For something like this, you have to create a new string - copying bits
from the old string and concatenating with the new:
set s to "fool"
set s to (text 1 thru 2 of s) & "a" & (character 4 of s)
s --> "foal"
Thus sharing is never an issue with simple data types - making 'changes'
can only be done 'via' copying.
You can, however, change the content of complex data types such as lists,
records and scripts. And this is where data sharing can catch out the
unwary - if you have two variables pointing to a single object, then both
will see any changes made to that object.
This stuff becomes much clearer once you understand the underlying
mechanics of AS, and realise that variable != object.
I think it would be more accurate to say that data sharing is *simply not
an issue* for simple data types, but is for complex ones. However, the ASLG
story is easier for non-programmers to understand. [As my high school
Biology teacher once told us: "We're going to teach you a lot of lies,
half-truths and gross over-simplifications in this subject, but as long as
you learn it all it'll get you through your exams just fine. Once you're in
university you can learn the real truth there."]
--
http://www.barple.connectfree.co.uk/ -- The Little Page of Beta AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.