Re: Script Object Order in Script
Re: Script Object Order in Script
- Subject: Re: Script Object Order in Script
- From: email@hidden
- Date: Wed, 25 Jul 2001 23:33:54 -0400
On Tue, 24 Jul 2001 19:13:45 +0200, Helmut Fuchs <email@hidden> pointed out,
>
> Is this a bug, or a feature? :
>
Can't answer this question, but I can make the script run: if you add
>
"my" to your reference of zzz it works fine:
>
>
script aaa
>
property whatever : "aaa"
>
end script
>
>
on CheckScriptProperties()
>
whatever of aaa --> "aaa"
>
whatever of my zzz --> "zzz"
>
end CheckScriptProperties
>
>
script zzz
>
property whatever : "zzz"
>
end script
>
>
CheckScriptProperties()
I think Chris Nebel explained a while ago what was going on inside the compiler.
When "whatever of aaa" is begin compiled, the symbol table has an entry for
"aaa" as a top-level script object. So the reference to "aaa" in "whatever of
aaa" is encoded as a reference to that object. But when "whatever of zzz" is
seen, "zzz" isn't in the symbol table. So the compiler decides this is a local
variable of the CheckScriptProperties function, and creates such an entry in the
symbol table. That local variable then masks the top-level script object zzz
when the script runs.
When you include "my", that prevents "zzz" from being entered in the symbol
table as a new local symbol, but forces it to be a top-level variable.
This seems buggy, but I can see how the problem arises, since the compiler needs
to turn the symbol name into an symbol table entry when it first sees it. The
"non-buggy" behavior would require a multi-pass compiler, or a language that is
more explicit about context (and thus would require a
more.complicated.heirarchy.like.Java for variable names), or a non-compiled
approach, where the variable names were kept as strings, and resolved
dynamically at run time, the way Lisp and Smalltalk do. (Lisp and Smalltalk are
not noted for their blazing execution speeds.)
--
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