Modifications and Variables - The Return ;-)
Modifications and Variables - The Return ;-)
- Subject: Modifications and Variables - The Return ;-)
- From: Axel Luttgens <email@hidden>
- Date: Thu, 09 Jan 2003 00:14:19 +0100
In a post dated January 3, Paul Berkowitz wrote (excerpt):
"Nevertheless, even after removing all properties
and globals, the script was showing a new modification
date every time it ran, even when run-only. By
explicitly declaring every top-level variable
(every single variable in the run handler) as local,
I succeeded in avoiding any modifications to the script
file.
So it seems that every undeclared variable in the run
handler, not just declared globals (which I knew about)
and properties, is persistent, even if its scope is local
to the run handler. (What put me on to this is the fact
that when you open a script in Script Debugger you can
read all the values of every top-level variable from its
last run.)"
I felt very unconfortable with the above: the underlying concepts of
globality and locality in these sentences were in deep contradiction
with my own truth about AppleScript.
So, I replied by submitting a summary of my understanding of the ASLG's
relevant parts:
"A variable declaration is the first valid occurence
of a variable identifier in a script.
Any variable declared at the top level of a script
is a global variable, unless explicitely declared
through a "local" statement.
The top level of a script must be understood as
including every statement that should appear in an
explicit run handler." [1]
My conclusion being thus that, according to the language's definition,
Paul really had implicitely declared global variables in his script
(before he explicitely declared them as local).
And that his script thus had persistent entities, hence the observed
behavior.
=======
Then followed a thread in which Paul and other people seemed to agree on
the idea that "top level variables" had a special status, that they are
distinct from "true globals". [2]
Damn! This made me still more uncomfortable...
In fact, every example provided in favor of the "special status" thesis
appeared to me in total compliance with the language's definition,
without needing any new concept. [3]
I could just see genuine global variables where others clearly saw
distinct beasts.
=======
I am thinking about this since some days: What am I missing? How could I
distinguish a "true global" from a "pseudo-global"? In what sense would
this "special status" be a real one?
I thus tried to see if could find a difference in the way the values are
saved in the script file.
I couldn't find one, but this is not really conclusive: I could have
missed lots of things.
I then downloaded the demo of Script Debugger for its variable watcher.
It doesn't seem to introduce a new category of variable and just keeps
happy with globals and locals (and properties) [4]
But again, this is not conclusive: it could just be an
over-simplification introduced by SD to make things appear easier.
So, if someone had a definitive answer about those matters...
TIA,
Axel
[1] Perhaps I could have better written the last sentence as follows:
"The top level of a script must be understood as
including the explicit run handler, if any".
[2] A "true global" would be one appearing explicitely in a 'global ...'
statement, being it at the top level or within a handler.
(I hope to have correctly rendered the idea)
[3] And in fact, I really don't see why the interpreter/compiler would
need such an elusive concept.
[4] This was the opportunity to test an assertion I made.
And yes, according to SD, even a script consisting of the single line
"set x to 3" indeed creates a genuine global variable.
Thanks LNS! I feel a bit less stupid...
_______________________________________________
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.