On 30.08.2011 0:04, Ariya Hidayat wrote:
Thanks, Dmitry! I also appreciate the elaborate explanation of
environment vs context.
The term "environment" is usually used to track scope storage (that is,
variables, formal parameters of activation etc.) All this come from the
concept of "activation record" which stores arguments on the stack and
remove the form the stack on return from function (it was called
"activation object" in ES3). The term "environment" in contrast is more
abstract and suppose highly abstracted entity which is not required to
be stored e.g. on the stack (but, e.g. in registers of VM or in heap --
to form a closure).
Regarding compilers and interpreters, the term "environment" is used
exactly for this purpose (as a table of bindings -- variable names to
their values) in canonical literature on the topic such as: SICP
(Structure and Interpretation of computer programs,
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-21.html#%_sec_3.2),
PLAI (Programming languages: Application and Interpretation) and EoPL
(Essentials of programming languages). Yes, the title of my series is
turned out similar to the later book ;) though, I didn't read it yet,
just started -- but the term "environment" is used there also, as well
as in two mentioned books.
Term "context" perhaps also can be used, but exactly "environment" is
mostly used for this structure in academic literature. "Context", or
even better to say "Execution context" is also of course related with
activation of a code (of a function usually) and it underlines, that
_besides_ the environment, the runtime needs some _additional_
information. For example, in ES3 execution context has the following
structure:
ContextES3 = {
Variable / Activation Object: { ... } // environment
ScopeChain: { ... } // VariableObject + list of parent scopes
ThisValue: context object, `this` value
}
I.e. the storage of variables is exactly VO (variable object) or AO
(activation object). But the whole structure which is placed onto the
execution stack -- is the execution context. In ES5 execution context
has the following structure:
ContextES5 = {
LexicalEnvironment: { ... },
VariableEnvironment: { ... },
ThisBinding: <this>
}
And again we see that "environment" and "context" are separated in
meaning. And since in your case you use the storage for bindings -- it's
an "environment" (the record of variables). But, you may still you term
"context", though, it's too "heavyweight" since you don't track
additional information for execution.
Additional info:
http://dmitrysoshnikov.com/ecmascript/es5-chapter-3-1-lexical-environments-common-theory/
http://dmitrysoshnikov.com/ecmascript/es5-chapter-3-2-lexical-environments-ecmascript-implementation/
Dmitry.
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]