Passed lists, references, and occasional errors
Passed lists, references, and occasional errors
- Subject: Passed lists, references, and occasional errors
- From: "Nigel Garvey" <email@hidden>
- Date: Sat, 19 Apr 2008 13:40:50 +0100
This script is contrived to illustrate something I ran into this morning:
on aHandler(aList)
script o
property l : aList
end script
item 1 of o's l
end aHandler
try
repeat with i from 1 to 100
aHandler(characters of "abcdefghijklm")
end repeat
on error msg
display dialog msg & return & "on iteration " & i & "."
end try
Most times, on both my Jaguar and Tiger machines, it displays a message
to the effect 'Can't get item 1 of characters of "abcdefghijklm". on
iteration 34.' (The iteration number seems to depend on the speed of the
machine, the way the script's run, and the length of the string.) When
it's run without the 'try' block in Script Editor, the line 'item 1 of
o's l' is highlighted by the error. The questions that puzzle me are:
1. Why does it only error sometimes?
2. How does the handler know that the list is derived from the characters
of "abcdefghijklm"?
The error never occurs if:
1. The handler's passed an _explicit_ reference.
aHandler(a reference to characters of "abcdefghijklm")
2. The characters are explicitly 'got' beforehand.
aHandler(get characters of "abcdefghijklm")
3. o's l is initialised to an explicitly dereferenced aList.
on aHandler(aList)
script o
property l : aList's contents
end script
4. o's l is _set_ to aList.
on aHandler(aList)
script o
property l : missing value
end script
set o's l to aList
5. aList is used instead of o's l in the problem line.
item 1 of aList
Words of one syllable, please.
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden