Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mdeh

macrumors 6502
Original poster
Jan 3, 2009
345
2
One of the frustrating things, is reading about new things, ( eg blocks and lexical scope) and seeing terms that have no definition.

Such is this one " Top-level environment" which has plenty of hits on Google, but no where is this defined, that I can find.

Could one of the "computer-geeks" possibly define this type of environment?

Thanks
 
If you provide a link to the article in question it may help to provide some context for the answer.

I would assume that top level environment refers to the highest level of Mac OS X (namely the Cocoa layer rather than the lower level Core Services, Core OS and the Kernel layers).
 
If you provide a link to the article in question it may help to provide some context for the answer.
).



OK..


HTML:
http://en.wikipedia.org/wiki/Scope_(programming)


.
Scroll down to the heading that says "Static Scoping"
 
That seems a rather clunky description to me.

Static scope basically just means that the scope of a variable or function is worked out at compile time rather than runtime.



Well...I found this that perhaps is clearer???


14.4.1 Names, Locations, Values and Environments

We said earlier that a variable name in a Scheme program is associated with a location in which any kind of Scheme value may be stored. (Incidentally, the term “vcell” is often used in Lisp and Scheme circles as an alternative to “location”.) Thus part of what we mean when we talk about “creating a variable” is in fact establishing an association between a name, or identifier, that is used by the Scheme program code, and the variable location to which that name refers. Although the value that is stored in that location may change, the location to which a given name refers is always the same.

We can illustrate this by breaking down the operation of the define syntax into three parts: define

creates a new location
establishes an association between that location and the name specified as the first argument of the define expression
stores in that location the value obtained by evaluating the second argument of the define expression.
A collection of associations between names and locations is called an environment. When you create a top level variable in a program using define, the name-location association for that variable is added to the “top level” environment. The “top level” environment also includes name-location associations for all the procedures that are supplied by standard Scheme.

It is also possible to create environments other than the top level one, and to create variable bindings, or name-location associations, in those environments. This ability is a key ingredient in the concept of closure; the next subsection shows how it is done.
 
I think that terminology is more prevalent in the Scheme world which I have very limited experience with. I doubt you would hear many C or Objective-C programmers talking about "top level environments".

As with most things in computing terminology changes with the context it is used in.

Still it was interesting to see that second text, thanks.
 
The most similar concept I can think of would be namespaces in C++, and the use of the scope resolution operator, ::.

In plain C, while there is definitely scope, as you dive down into deeper nested scope, using a variable name that is defined in a higher scope can be done, but you can no longer access a variable with the same name with a higher scope. There's no way to say you'd like the x with global scope if you have one with, say, the scope of the current for loop.

-Lee
 
Yes, when I saw "top level environment" I thought it was a thread about Lisp.

It is the outermost scope in an execution stack.

C++ namespaces are completely unrelated.
 
Nested namespaces are similar (in concept) are they not?

It is a type of scoping, but it's not the same.

At a point in the execution, you have a dynamic environment and a lexical environment. When navigating the stack with a debugger you can examine the lexical and dynamic variables in the current environments.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.