-
Notifications
You must be signed in to change notification settings - Fork 3
lexical shadowing of inst var keys by normal dcls is a hazzard #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
My intention is to have the scope chain for that example look like this: [
{ // Class identifier scope
"Point": class Point
},
{ // Instance var declaration scope
"x": uninitialized,
"y": uninitialized,
"%x": instance_var_key_1,
"%y": instance_var_key_2
},
{ // Instance var scope (special lookup rules!)
"x": instance_var_key_1,
"y": instance_var_key_2
},
{ // Function/parameter scope
"x": argument_0,
"y": argument_1
}
] Using the non-identifiers "%x" and "%y" to implement a separate namespace for use by instance variable member expressions. (Perhaps there's a less hacky way to implement the separate namespace?) The expression: this->x would look up "%x" in the scope chain. It would find an entry for "%x" in the "instance var declaration scope" and use the binding value (an instance variable key) to access the correct instance variable in Does that make sense? |
OK, I see. You do have a parallel scope chain (whether it is modeled as a separate env record or via non-identifier names amounts to the same thing) at this level of discussion. But the implicit inst var scope around methods still seems to mess up your implicit inst var reference syntax: constructor (x,y) {
x = x; //want to set instance var to value of parameter
y = y;
} Personally, I highly dislike implicit |
I thought you might 😄 . But I wanted to play with the idea of using function C() {
let x = 0;
this.getX = () => x;
} And I think one would expect the "implicit" An advantage of using |
Well, I also dislike repurposing I see if we use existing declarators like BTW, In my proposal, I think requiring a . in front of the identifier in private declarations would be fine: |
The idea is that, while repurposing I think we should continue to explore both this avenue and your strawman in parallel. I've added a few examples for the instance variables strawman here. My experience from coding these examples:
|
If we repurpose an existing declarator keyword to have a special meaning within a class body, I would prefer using Or a new completely new contextual keyword, such as I really don't like having to add a per instance slot and a per instance closure for each "private method". As I mentioned at last week's meeting. Large classes could have lots of private methods but very simple inst var and own data property state. Adding per instance private method state turns small but algorithmically complex objects into large objects. Increases memory pressure, allocation cost, etc. But here's a thought. How about: class Counter extends HTMLElement {
var x = 0; //defines an instance variable with a construct time initializer
->clicked(){ //defines a private method, shared by all instances
this->x++; // always need to explicitly qualify inst var and private method references
window.requestAnimationFrame(_=>this->render());
}
->render(){this.textContent = this->x.toString()}
constructor() {
super();
this.onclick = args => this->clicked(...args); // or this->clicked.bind(this)
}
connectedCallback() { this->render(); }
static {
window.customElements.define('num-counter', this);
}
} |
I considered (and actually quite like) I'm also curious about expanding this to
Very true. For instance var closures that are assigned once, only called, and never reified as objects, do you think an implementation could internally share the function? Interestingly, some developers are already doing this kind of thing to get autobound "methods". I ran across this example today. |
If that was the only push back we got, I'd be thrilled. Better to contextually change the meaning of |
Closing in favor of #7 |
I initially kind of liked what you were doing with your instance var key lexical bindings. But the first example I tried ran into this:
The text was updated successfully, but these errors were encountered: