• 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: handler failure
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: handler failure


  • Subject: Re: handler failure
  • From: email@hidden (Michael Sullivan)
  • Date: Wed, 13 Nov 2002 11:26:46 -0500
  • Organization: Society for the Incurably Pompous

email@hidden (has) writes:
> Chris Espinosa wrote:

> >A handler is essentially a property in your script, and you can set it
> >to any value, including that of another function.

> Unfortunately, this [undocumented] behaviour has always been broken:

> script a
> property _val : 1

> on foo()
> return _val
> end foo
> end script

> script b
> property bar : missing value
> end script

> a's foo()
> --> 1

> set b's bar to a's foo
> b's bar
> --> <<handler foo>> --!!!!!

That's actually correct behavior. When you refer to a function without
the parens, it should return the function itself (or a reference). The
problem is that when you actually call the function, it does the same
thing:

> b's bar()
> --> <<handler foo>> --!!!!! Now I really mean the exclamation points.

When you copy a handler like that, you are giving it a new lexical scope
(that of script b) in which there is no property '_val' in scope. Of
course, I still think that should error, rather than return the handler,
at least when called.

If you want to pass that handler around, you need to specify a's _val in
it.

so:

script a
property _val : 1

on foo()
return a's _val
end foo
end script

script b
property bar : missing value
end script

a's foo()
--> 1

set b's bar to a's foo
b's bar -- note no parens, so this is a reference, not a function call
--> <<handler foo>>
b's bar()
--> 1


I was hoping that I could set b's bar to a reference to a's foo and have
this all work out correctly (then there would be no copy, and so no
context change -- it should keep the original scope, right?). But once
I did that, I couldn't figure out how to actually *call* the function
using that reference variable.

i.e.:

script a
property _val : 1

on foo()
return _val
end foo
end script

script b
property bar : missing value
end script

a's foo()
--> 1

set b's bar to a reference to a's foo
b's bar()
--> error: <<script b>> doesn't understand the bar message.

If I try to do:

(get b's bar)()
--> syntax error, will not compile.

but:

get b's bar
--> foo of <<script a>>

So this is a bit of a difficulty, IMO.


Michael

--
Michael Sullivan
Business Card Express of CT Thermographers to the Trade
Cheshire, CT email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: handler failure (From: has <email@hidden>)

  • Prev by Date: Re: Entourage: Kill that Daemon! (Shell)
  • Next by Date: Re: handler failure
  • Previous by thread: Re: handler failure
  • Next by thread: Re: handler failure
  • Index(es):
    • Date
    • Thread