Re: Adding To A List
Re: Adding To A List
- Subject: Re: Adding To A List
- From: kai <email@hidden>
- Date: Thu, 2 Jun 2005 09:47:59 +0100
On Thursday, June 2, 2005, at 08:27 am, DigitEL wrote:
Can anyone suggest why the following code which I am trying to create
a list of incremented lists returns a list with all of the contained
lists equal to the last list incremented?
set currentList to {1, 2, 3, 4}
repeat until (item 1 of currentList) is greater than or equal to the
stopCount
set item 1 of currentList to ((item 1 of currentList) +
the nextIncrement)
set item 3 of currentList to ((item 3 of currentList) +
the nextIncrement)
set the end of the newList to currentList
end repeat
In two words: data sharing.
This feature, which makes the use of large data structures more
efficient, affects classes such as lists, records, dates and script
objects. Essentially, it means that the same data can belong to
multiple structures so that, when one structure is updated, the others
are automatically updated.
Very handy at times, but I guess it's caught most of us out at one
stage or another. To create an independent structure, you need to use
the 'copy' command. Try changing the last statement in the repeat loop
to:
----------------
copy currentList to end of newList
----------------
---
kai
_______________________________________________
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