2 ms·
It seems really confusing that the context object becomes an implicit `this`. It is already hard enough to understand what scope a name will be looked up in. Ma
by captainmuon 4y ago
It seems really confusing that the context object becomes an implicit `this`. It is already hard enough to understand what scope a name will be looked up in. Many languages suffer from this when they have a kind of `with` block. Ironically, VB6 gets it right. There you have to qualify members with a leading dot, if they are to be looked up in the context, e.g.:
' Haven't written this in 20 years so maybe it is not 100% correct :-)
With myForm
.Title = "Hello World"
.Maximize()
End With
When I heard "context receivers", I thought something completely different and got excited: Sometimes you need to pass a parameter to a function that only gets called several levels deep. It is ugly to add that parameter to every intermediate function. But it is even worse to add a global variable. The OOP solution would be to put all the functions as methods on an object, and pass the data via a field on the object. But what if you could pass the parameter like this (pseudocode):
function outer() {
use-extra-context(logcolor="RED") {
foo();
}
}
function foo() { bar(); }
function bar() { baz(); }
function inner() takes-extra-context(logcolor) {
print("Something", color=logcolor);
}
Basically something like dynamical scope, or thread local storage. (Or reading from the other comments, maybe this proposal does just that and I missed something?)