On 16.04.2011 0:45, Sam Tobin-Hochstadt wrote:
On Fri, Apr 15, 2011 at 4:32 PM, Dmitry A. Soshnikov
<[email protected]> wrote:
OK, what I was saying is that you mixing the terminology calling as "dynamic
scope" the "runtime bindings". And I mentioned that the dynamic scope is
when a binding is resolved in the respect to the _callee_, but not in
respect of the _definition place_ (i.e. _lexical_ place in the source code).
var foo = 10;
function bar() {
console.log(foo);
}
(function () {
var foo = 20;
bar(); // 10 in static scope, 20 in dynamic scope!
})();
I understand how dynamic scope works. And ES5 with the mutable global
object has it:
function bar() { return foo };
bar() // error: foo is not defined
var foo = 7;
bar(); // produces 7
Lexical scope would produce the error both times.
Just a small nit-picking: (1) you shouldn't use `var`, (2) lexical
addressing will produce the only compile-time error on "foo is not
defined" (since you write it as just `foo = 7`).
But I'm of course agree that avoiding of runtime bindings and allowing only
of static bindngs (i.e. those names which directly are resolved at compile
time and _therefore_ the direct map of their addresses can be built -- to
avoid scope chain lookup) is good -- from both sides -- to make these errors
as early and (as usually it is) O(1) bindings resolution approach without
any scope chain lookup.
2. Again, the reason that Dave and I have worked hard to avoid holes
in the lexical scoping of identifiers in modules is for programmers to
understand programs -- not for efficiency at all.
Yes, it's OK, I got it.
I don't know what
else to say to persuade you of this, but making identifier resolution
fast is not "the main reason".
Oh, it's not required, I got it. And I also won't persuade you, but just
suggest this resource
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-35.html#%_sec_5.5.6
(the whole book is also recommended to be read if not yet).
I first read SICP a long time ago :)
Well, then you should know that the mentioned above chapter from the
book is exactly about what I was saying, i.e., again -- "let's make
lexical addressing to make fast lookup".
Dmitry.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss