I thought I more or less understood Applescript but I have never noticed this before. Hope I’m not being really thick here.
Why/how does the first routine, with the set item command, change the original variables but the second routine does not? What is the linkage?
I need to be able to save a list, access non contiguous values in the list and then retrieve the original list. So far, I can’t do this. The (I thought) saved list is overwritten.
Thanks for the help.
set thisList to {1, 2, 3}
set saveThisList to thisList
set ret to test(thisList)
--set ret to test2(thisList)
return thisList # RESULT: {0,0,0}
-- return saveThisList # SAME RESULT: {0,0,0}
# THIS DESTROYS THE ORIGINAL LIST:
on test(theInput)
repeat with k from 1 to 3
set item k of theInput to 0
end repeat
return "whatever"
end test
# BUT THIS DOESN'T:
on test2(theInput)
repeat with eachItem in theInput
set eachItem to 0
end repeat
return "whatever"
end test2
Model: MacBook Pro
AppleScript: 2.7
Browser: Safari 605.1.15
Operating System: macOS 10.14