Re: Modifications and Variables
Re: Modifications and Variables
- Subject: Re: Modifications and Variables
- From: has <email@hidden>
- Date: Sun, 5 Jan 2003 23:54:10 +0000
[sorry - meant to post this earlier and forgot, but might still be
useful to the discussion at hand]
Paul Berkowitz wrote:
On 1/4/03 11:26 AM, "Axel Luttgens" <email@hidden> wrote:
With above examples in mind, I may now briefly summarize my
understanding of the ASLG about those matters (especially pp. 303-304
> and 311-316):
>
> Any variable declared at the top level of a script
is a global variable, unless explicitely declared
> through a "local" statement. [...]
>
And I should add (a bit provokingly?) that an explicit run handler
appears to me more as a cosmetic matter than anything else; there is no
such handler, there are just top level statements.
My own feeling is the opposite: that the "top-level statements" thing
is just a compiler fudge, used to make AS look simpler to users. If
the compiler finds statements floating around loose and no explicit
'run' handler declaration, it effectively creates one and groups the
loose statements into it. You'd really have to ask an AS engineer
though.
The muddy area is the statement that all top-level variables are global.
I think "muddy" is too kind. ;p
I'd stick my neck out and say the ASLG is wrong; or at best mighty
misleading. But then, variables in AS have always been a bit ropey
(c.f. past discussions of flaws in AS's static & dynamic variable
binding, for example).
Maybe it would be better
if top-level variables really were globals that needed to further
declaration?
I think it'd be best if top-level variables behaved strictly as
locally-scoped variables. (I can specify reasons if necessary, but
they're not hard to figure out.) I can't help feeling the current
behaviour might be more leaky implementation than logical design (if
there are particular reasons for it, I'd be interested to hear).
I guess much of the problem derives form the fact that you aren't forced to
declare variables explicitly in AppleScript - either as to scope or type.
(Why Paul, I didn't know you were into Whips and Chains...;p)
The real source of confusion
is that the top-level (or run handler) undeclared variables behave as
globals for persistence
Yup. Though I think it'd be clearer just to say that "globals,
properties and top-level vars are all persistent".
Anyway, as well as manipulating top-level variable's scope:
on foo()
global i
return i
end foo
set i to true
foo() --> true
a handler can also scope its own variables as global:
on foo()
global i
set i to true
end foo
foo()
get i --> true
Frankly though, these behaviours give me the cold shakes and I'd
never advocate their use. I've a gut feeling that user-declarable
globals in AS are all but redundant, and a Bad Idea in general; and
it'd be better for AS and its users if only local variables and
properties were available [1]. These provide all the functionality
coders really need, it'd make the language simpler and easier to
learn, and it's one less thing to go wrong at the end of the day.
HTH
has
[1] I doubt we'll see any changes in AS 1.x, but perhaps AS-X will go
a long way in cleaning out the old cruft and clutter and improving
syntax and semantics.
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
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.