Re: List acting like a global
Re: List acting like a global
- Subject: Re: List acting like a global
- From: Nigel Garvey <email@hidden>
- Date: Thu, 6 Dec 2001 00:47:50 +0000
Jason Bourque wrote on Wed, 05 Dec 2001 09:56:44 -0500:
>
Hello,
>
>
What's Happening?
>
>
tell application "Finder"
>
set aList to name of every item of desktop
>
end tell
>
>
tell me to srListIndexer(aList)
>
>
>
>
-- sr2ndListItemFromIndexOf1stList
>
set vItemWithIndex to "3 Paper Alligator"
>
>
-- Capture the current delimiter for AppleScript
>
set vTids to the AppleScript's text item delimiters
>
set the AppleScript's text item delimiters to " "
>
>
set vItemIndex to (item 1 of text items of vItemWithIndex) as number
>
>
-- Reset the delimiter for AppleScript to its previous call state
>
set AppleScript's text item delimiters to vTids
>
>
item vItemIndex of aList
>
--> "3 Paper Alligator"
>
>
-- Should be "Paper Alligator"
>
-- What's happening?
It's because your handler srListIndexer(aList) prepends numbers to the
names in the list. :-) The list inside the handler *is* the one passed.
Only the variables (whose values are merely pointers to it) are local or
global, not the list itself. The simple way to leave the original list
intact is to make a copy for use within the handler:
on srListIndexer(vAnyList)
copy vAnyList to vAnyList -- set the variable to a duplicate list
-- work on the copy
end srListIndexer
The same applies to any complex object, such as records, dates, folders,
application objects, etc.
NG