Re: Looks like a bummer
Re: Looks like a bummer
- Subject: Re: Looks like a bummer
- From: email@hidden
- Date: Thu, 14 Dec 2000 23:17:24 -0500
On Wed, 13 Dec 2000 21:45:42 -0800, Richard 23 <email@hidden> asked,
>
Is it possible for a script applet to modify a record passed to it,
>
with the modification reflected in the caller?
>
>
I've come to the conclusion that it's not which is a bit of a drag.
No. Although you can use 'foo(a reference to myRecord)' to do a
call-by-reference to a handler within the same script, you can't pass an object
reference as a parameter of a user function to a separate applet.
The best I could come up with was, "a reference to x of current application",
which generates an Apple Event with an object reference, "obj {form:usrp,
want:type(prop), seld:"x", from:'null'()}" in AETEGizmo's display. This is a
correct reference, "the user property named "x" of the application." But that
gives a "can't make data into the requested type" after the event is sent.
If I look at AETracker's log, here's what I see. I have the script applet "Bar"
that looks like this
property q : {myLabel:12}
set p to a reference to q of current application
tell application "Foo"
foo from p
end tell
Script applet "Foo" looks like this.
to foo from x
return 42
end
The log shows Bar sending the "foo from (object specifier)" to Foo. Foo then
tries to resolve the object specifier, constructing a "get data" Apple Event.
But it send the "get data" message to itself. Which fails.
Since the reference is "q of current application", I guess that meaning is
changing as the application changes. Which is confirmed when I put 'property q
: "Hi"' into script Foo. Then, I get no errors.
So I tried, 'set p to a reference to q of application "Bar"' That gave no
error, but Foo wasn't able to change the data. And I didn't see any "set data"
message from Foo back to Bar. Pulling out AETEGizmo again, I see that this
convoluted reference gets evaluated back down to just {myLabel:12}, and we're
back to 'call-by-value.'
It seems like the reference either gets resolved to early (sending the value),
or is resolved too late (sending a reference, that is then interpreted with
'current application' in the context of the receiver).
What this is doing isn't call by reference, but call by name. Things are
interpreted the way Lisp does things. And R23 wants behavior like Algol, which
would require the reference to be bound with its context, as a thunk.
I'd advise R23 to look at the exchange of information that occurs in the Apple
Events when you send these reference around, and then he won't worry about the
minor overhead of copy data to take the result and store it back Since Apple
Events are so slow, you'll have to have an awful lot of data before the copying
takes any significant time. So just write,
tell application "Foo"
frobnicate from myBigList returning myBigList
end tell
and don't worry. Let the computer do the work, and focus on the other issues of
World Domination. (Where will your Evil Lair be? Make sure your read through
"The Top 100 Things I'd Do If I Ever Became An Evil Overlord"
<
http://www.hax.com/eviloverlord/lists/overlord.html> )
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden