• 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
copy & set statments
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

copy & set statments


  • Subject: copy & set statments
  • From: David <email@hidden>
  • Date: Sat, 20 Oct 2001 22:50:53 -0500

In this script at the end of execution:
s = 5
J = 2
n = 9

set n to 2
set s to 5
set j to n
set n to 9

My question relates to the behavior of J. In the script above J is the value of what n was before N was changed. However, in the script below the behavior is much different. The behavior of the script below is different because the variable theList is changed even though it is not directly changed by the script. Why does nAList act like it is the variable theList even though theList is not being used in that example?

set theList to {{1, 2, 3, 4, 5}, {78, 79, 69, 36, 23}}

set newList to {}
set nAList to {}

repeat with l from 1 to count of items of theList
set newList to newList & item l of theList as list
--merge the list into a list that is not a list of lists
end repeat


-->lines of interest
set theList to newList
copy newList to nAList
-- but if the line above would read what the line below says-set nAList to newList
--set nAList to newList

repeat with n from 1 to count of items of nAList
set sliced to "klk"
set item n of nAList to sliced
end repeat

return {nAList, theList}

(*--> result from the copy statement {{"klk", "klk", "klk", "klk", "klk", "klk"
, "klk", "klk", "klk", "klk"}, {1, 2, 3, 4, 5, 78, 79, 69, 36, 23}}

--> result from the set statement {{"klk", "klk", "klk", "klk", "klk", "klk"
, "klk", "klk", "klk", "klk"}, {"klk", "klk", "klk", "klk", "klk", "klk", "klk"
, "klk", "klk", "klk"}
*)

Have I had to much Mtn Dew, misunderstood the definition of the set statement or did I catch an undocumented gotcha?


scratching my head,
David Dittmann


  • Prev by Date: Re: applescript-users digest, Vol 2 #1218 - 10 msgs
  • Next by Date: Re: Converting an applescript from 68k app to PPC
  • Previous by thread: Re: applescript-users digest, Vol 2 #1218 - 10 msgs
  • Next by thread: Re: copy & set statments
  • Index(es):
    • Date
    • Thread