On 15.04.2011 23:56, Sam Tobin-Hochstadt wrote:
On Fri, Apr 15, 2011 at 3:40 PM, Dmitry A. Soshnikov
<[email protected]>  wrote:
On 14.04.2011 23:40, Sam Tobin-Hochstadt wrote:
On Thu, Apr 14, 2011 at 3:29 PM, Dmitry A. Soshnikov
<[email protected]>    wrote:

But these globals won't be accessible to scripts that have already been
compiled; only to scripts that are subsequently compiled and evaluated,
e.g.
via ModuleLoader.eval.
Which again seems as in chaise of efficiency, let's take away (a little
of)
convenience from a user.
This isn't about efficiency at all!

The reason that Dave and I have worked hard to make modules lexically
scoped, of which this is a part, is so that when you look at a
program, you can understand what it does.  This is a fundamental part
of programming, and not having a clear binding structure in your
language makes it much harder.

Sometimes, this makes your program more efficient, too, because the
compiler understands your program better for the same reasons that you
can understand your program more easily.  But that really isn't the
point.
Actually, ECMAScript is already lexically scoped language (in respect of
closures). I think there's a mess with treating a possibility of creating a
binding at runtime with the dynamic scope. Dynamic scope
(http://bit.ly/hz7tT2 -- just for interested) is an early design flow in PLT
backing to Lisp invention times (where language authors have no much
experience). Perl e.g. still has both -- dynamic and static scopes. But JS
has/had lexical scope.

Yes, `with` and `eval` (direct, non-strict) _are_ the features which brings
dynamics to the static scope of ES. And I always thought (and it seems quite
logical) that the direct lexical mapping of ids (which is the reason of
disallowing of creating of runtime bindings) is exactly to improve the
identifier resolution and technically it's the main reason. Avoiding object
to represent a scope and avoiding a scope chain consisting of these object
is the reason of providing direct map of "variable name : direct address"
which (theoretically?) is accessed in O(1).
1. The global object (which is what's originally under discussion
here) also gives you "dynamic scope" for top-level variables.

window.fooish = 7
  7
fooish
  7


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!
})();

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).

Dmitry.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to