• 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: Creating list references in handlers. Bad code or bug?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating list references in handlers. Bad code or bug?


  • Subject: Re: Creating list references in handlers. Bad code or bug?
  • From: Victor Yee <email@hidden>
  • Date: Fri, 14 Sep 2001 10:21:07 -0400

On Fri, 14 Sep 2001 09:38:33 -0400, Paul Skinner wrote,

> Can anyone point out my error, or is this a bug?

I think that the problem is a matter of scope. References can only refer to top-level or global varaibles. And remember that variables defined inside handlers are considered local unless explicitly declared as global.

For example:

set theList to {9, 8, 7}

on theHandler()
set theList to {1, 2, 3}
set listReference to a reference to theList
{contents of the listReference, theList}
end theHandler

theHandler()
--> {{9, 8, 7}, {1, 2, 3}}

> on theHandler()
> set theList to {1, 2, 3}
> set listReference to a reference to theList
> return listReference
> -->theList of +script;
> end theHandler

This is the same result as setting a reference at the top-level:

set listReference to a reference to theList

listReference
--> theList of <<script>> (Note that this is the result without "theList" being defined.)

So your error:
> -->Error -1700: Can't make some data into the expected type.
Is the result of trying to dereference a non-existent variable (remember that references need to point to top-level or global variables and that variables inside handlers are considered local by default).

on theHandler()
global theList
set theList to {1, 2, 3}
set listReference to a reference to theList
{contents of the listReference, theList}
end theHandler

theHandler()
--> {{1, 2, 3}, {1, 2, 3}}

Victor


  • Prev by Date: Re: Creating list references in handlers. Bad code or bug?
  • Next by Date: Re: Creating list references in handlers. Bad code or bug?
  • Previous by thread: Re: Creating list references in handlers. Bad code or bug?
  • Next by thread: Re: Creating list references in handlers. Bad code or bug?
  • Index(es):
    • Date
    • Thread