GulfOfMexico icon indicating copy to clipboard operation
GulfOfMexico copied to clipboard

Add scope exposing

Open hwgn opened this issue 2 years ago • 9 comments

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.

hwgn avatar Jun 14 '23 09:06 hwgn

This could also be extended through exposing everything (expose to myFuncB - will act as if myFuncB's Scope began where the exposing scope ended)

hwgn avatar Jun 14 '23 10:06 hwgn

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.

stohrendorf avatar Jun 14 '23 16:06 stohrendorf

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?

hwgn avatar Jun 15 '23 09:06 hwgn

nice idea! I'll consider it

TodePond avatar Jun 15 '23 09:06 TodePond

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

stohrendorf avatar Jun 15 '23 10:06 stohrendorf

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.

hwgn avatar Jun 16 '23 09:06 hwgn

We could introduce "variable variables" (not the ones already defined), i.e. if var foo = "x"!, then $foo would resolve to variable x.

stohrendorf avatar Jun 16 '23 16:06 stohrendorf

We could introduce "variable variables" (not the ones already defined), i.e. if var foo = "x"!, then $foo would resolve to variable x.

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

hwgn avatar Jun 19 '23 12:06 hwgn

This is amazing

Bytestorm5 avatar Jun 22 '23 21:06 Bytestorm5