• 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
Re: Passed lists, references, and occasional errors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passed lists, references, and occasional errors


  • Subject: Re: Passed lists, references, and occasional errors
  • From: Philip Aker <email@hidden>
  • Date: Sat, 19 Apr 2008 05:55:09 -0700

On 08-04-19, at 05:40, Nigel Garvey wrote:

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

6.
on SomeHandler(theList)
script internal
property item_list : theList
end script
item 1 of internal's item_list
end SomeHandler

try
set inlist to (characters of "abcdefghijklm")
set lcount to count of inlist
repeat with i from 1 to lcount
SomeHandler(inlist)
end repeat
on error msg
display dialog msg & return & "on iteration " & i & "."
end try


Words of one syllable, please.

bjorked?


Philip Aker
echo email@hidden@nl | tr a-z@. p-za-o.@

Sent from my SE/30

 _______________________________________________
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

References: 
 >Passed lists, references, and occasional errors (From: "Nigel Garvey" <email@hidden>)

  • Prev by Date: Passed lists, references, and occasional errors
  • Next by Date: Applescript with Mail eat the Apple!…
  • Previous by thread: Passed lists, references, and occasional errors
  • Next by thread: Re: Passed lists, references, and occasional errors
  • Index(es):
    • Date
    • Thread