Re: list question
Re: list question
- Subject: Re: list question
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 03 Jun 2003 10:38:00 -0700
On 6/3/03 9:02 AM, "dialup" <email@hidden> wrote:
>
Can anyone tell me if I'm thinking wrong with this? If I run this code:
>
>
------------
>
set a to {"a", 1}
>
set b to a
>
set a's item 1 to "b"
>
return b
>
>
--> {"b", 1}
>
------------
>
>
>
but shouldn't b be {"a",1}? I'm running this in AS 1.6 on OS 9.2.2
Read the AppleScript Language Guide's relevant section on lists and records.
Lists and records "share data": i.e. they are dynamic. When you use the
keyword 'set', all variable instances set to the same list or record change
along with the instance you're changing, unlike what happens with strings
and numbers. (Dates are also dynamic.)
To avoid data sharing between instances of lists and records, use 'copy':
------------
set a to {"a", 1}
copy a to b
set a's item 1 to "b"
return b
--> {"a", 1}
------------
Under other circumstances. 'set' is preferred to 'copy' because it's lighter
on memory: 'copy' creates a while new instance in memory. When trying to
avoid data sharing between lists, that's precisely what you want to do. In
other circumstances, both the data-sharing feature and the conservation of
memory with lists and records is a great advantage. Use the method you need
in each situation.
--
Paul Berkowitz
_______________________________________________
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.