Add scope exposing
Introducing the keyword expose:
func myFuncA (x, y) => {
return x + y!
expose x to myFuncB!
}
func myFuncB () => {
return x!
}
print(myFuncB())! //undefined
print(myFuncA(1, 2))! //3
print(myFuncB())! //1
See changes for full feature description.
This could also be extended through exposing everything (expose to myFuncB - will act as if myFuncB's Scope began where the exposing scope ended)
I'd prefer this to be a stringly-typed function for maximum flexibility. I don't want to be limited by the compiler, but instead want to dynamically expose anything to anywhere at runtime.
I'd prefer this to be a stringly-typed function for maximum flexibility. I don't want to be limited by the compiler, but instead want to dynamically expose anything to anywhere at runtime.
How exactly do you envision that? Could you give an example?
nice idea! I'll consider it
I'd prefer this to be a stringly-typed function for maximum flexibility. I don't want to be limited by the compiler, but instead want to dynamically expose anything to anywhere at runtime.
How exactly do you envision that? Could you give an example?
In your example, expose("myFuncB", "x").
I'd prefer this to be a stringly-typed function for maximum flexibility. I don't want to be limited by the compiler, but instead want to dynamically expose anything to anywhere at runtime.
How exactly do you envision that? Could you give an example?
In your example,
expose("myFuncB", "x").
Couldn't you just create that function yourself?
fnc expose (where, what) => {
expose what to where!
}
Following the specification, this would expose what (as what!) to where, however to give it the right name, we'd indeed need some new language feature. Perhaps, calling something like .toString() would then use the actual string as the variable name:
fnc expose (where, what, name) => {
expose what to where as name.toString()!
}
Using an expression inside the expose statement could make it calculate only at runtime.
We could introduce "variable variables" (not the ones already defined), i.e. if var foo = "x"!, then $foo would resolve to variable x.
We could introduce "variable variables" (not the ones already defined), i.e. if
var foo = "x"!, then$foowould resolve to variablex.
This might fit best as a seperate suggestion/issue/PR. This could finally be the language that allows generation of variables, as in the way I imagined loops before knowing anything about programming:
for (var var i = 0; i < 10; i++) { // disregard the syntax, the message matters
expose i as $i + "variable"!
}
print(3variable) // 3
This is amazing