Re: Coerce String to Handler?
Re: Coerce String to Handler?
- Subject: Re: Coerce String to Handler?
- From: Chris Nebel <email@hidden>
- Date: Mon, 16 Apr 2001 14:30:58 -0700
- Organization: Apple Computer, Inc.
Brennan Young wrote:
>
Jeffrey W Baumann <email@hidden> wrote
>
>
> I think what we need is something analagous to Javascript's "eval"
>
> function.
>
>
That would be nice, and considering Applescript's LISP roots, it's
>
surprising we don't have this yet.
>
>
Lingo has a neat feature where you can use a 'symbol' datatype for a
>
handler name ...
While AppleScript does have code to convert strings to handlers and back
(it sort of has to in order to handle cross-script function calls),
there's no way to get to it through the language. There's an
enhancement request on this.
In the meantime, you can assign handlers to variables, so you can do
things like this:
to frotz(a) ...
to nitfol(a) ...
if gondar()
set x to frotz
else
set x to nitfol
end
x(42) -- calls frotz or nitfol, depending.
So you can bind any known-in-advance handler to a variable, but you
can't do it based on an arbitrary string.
--Chris Nebel
AppleScript Engineering