• 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: Inheritance, Context, Scope, etc.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inheritance, Context, Scope, etc.


  • Subject: Re: Inheritance, Context, Scope, etc.
  • From: Michael Terry <email@hidden>
  • Date: Fri, 23 Jan 2004 14:40:06 -0800

On Jan 23, 2004, at 10:32 AM, Wallace, William wrote:

But I still wouldn't mind hearing from Mr. Nebel (or anyone else who may know) about the underlying philosophy for this behavior. I now know how to enable child script objects to change the value of their parent's global variables, but I'm still curious as to why it is forbidden for a child script object to be able to set the initial value for a parent's global variable (I mean how could this be a bad thing?).

I don't think it was a philosophy per se, but more of an implementation detail. It's not only who children can't access their parents' unset globals. For instance:

script a
global b
end script

set a's b to 1
--> error

Unlike many other languages, AppleScript doesn't create space for a variable when it's declared. AppleScript is dynamic; it doesn't have any preconceived notions about the type or data size of a value that will be held in the variable. Coupled with this fact, we can infer from the behavior we've been discussing that uninitialized variables simply don't exist, regardless of whether they've been declared. Compare the error messages you get in the following two examples:

get a
--> The variable a is not defined.

global a
get a
--> The variable a is not defined.

No difference. Of course, that's not conclusive, but I think it's suggestive. Instead of creating a variable then, variable declarations allow the scripter to explicitly specify what type of scope the variable will have. It's basically a hint for the AS interpreter, which would otherwise give it a scope based on its somewhat complex, default criteria.

So, the AS interpreter goes along--as it comes across variable declarations--it starts keeping a little list: OK, k's a global, myList's a local, etc. The first time it comes to a variable being initialized, it checks its list to see if any particular scoping limits should be attached to the variable. If not, it attaches a default scope to it, and moves on. The point is, the declarations are only there so AS can make this little list. If you try to call into the scope to set a variable's value, it doesn't matter if the variable name is in this list, it needs to exist in a more fundamental way.

When you look at it that way, it seems obvious: Why would you be able to create new variables in one script from a separate script? That would be a strange thing to be able to do.


Mike
_______________________________________________
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.

  • Follow-Ups:
    • Re: Inheritance, Context, Scope, etc.
      • From: Paul Berkowitz <email@hidden>
References: 
 >RE: Inheritance, Context, Scope, etc. (From: "Wallace, William" <email@hidden>)

  • Prev by Date: Re: styled text to record, ok. But record to styled text?
  • Next by Date: Re: Inheritance
  • Previous by thread: RE: Inheritance, Context, Scope, etc.
  • Next by thread: Re: Inheritance, Context, Scope, etc.
  • Index(es):
    • Date
    • Thread