• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scope of globals, parents and children, "load script" an
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scope of globals, parents and children, "load script" an


  • Subject: Re: Scope of globals, parents and children, "load script" an
  • From: Timothy Bates <email@hidden>
  • Date: Sat, 19 May 2001 15:05:43 +1000

On 5/18/01 4:52 PM, "email@hidden" <email@hidden> wrote:
> Any handler (which includes the implicit run handler of the main script) that
> wants to use a global variable must declare it as such. The philosophy is
> that an outsider can't steal a handler's variables. That is, an outside bunch
of
> code should not be able to change the meaning of code inside a handler by
> declaring a variable global.
>
> If I write,
>
> on foo(x)
> set i to 0
> set x2 to x & x
> set x3 to x2 & bar(x)
> return x3 & (i as string)
> end foo
>
> Then it is a good thing that foo() doesn't unintentionally destroy the global
> variables i, x2, and x3, just because some code outside foo() declared "global
> x2". Its also good that bar() can't reach into foo() modify i when bar() is
> called.

Isn't that exactly what happens? For example in the code below, my global
"i" has been set to 0 and was accecssed implicitly by bar() without be
declared.


global i
set i to 100

foo(1)

return i
-->0

on foo(x)
set i to 0
set x3 to bar(x)
end foo

on bar(x)
return i
end bar


References: 
 >Re: Scope of globals, parents and children, "load script" an (From: email@hidden)

  • Prev by Date: Re: Apple Events vs. AppleScript
  • Next by Date: Re: Re: Impossible "If"?
  • Previous by thread: Re: Scope of globals, parents and children, "load script" an
  • Next by thread: Re: Scope of globals, parents and children, "load script" an
  • Index(es):
    • Date
    • Thread