Skip to content
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

Add a !global construct #3

Open
suve opened this issue Dec 14, 2017 · 1 comment
Open

Add a !global construct #3

suve opened this issue Dec 14, 2017 · 1 comment

Comments

@suve
Copy link
Owner

suve commented Dec 14, 2017

Currently functions have unfettered access to variables in higher scopes - be it the program's globals, or the caller's variables. This is a really stupid design decision that should be changed.

Proposed solution:

  • Limit functions to accessing only their local variables (and args/statics)
  • To use global variables, one must explicitly declare their use with !global $varname
  • The construct should probably be limited to the function's top-level scope (can't be put inside !if or loops)

Things to consider:

  • Should !global $var and !global &var be equivalent, or should the first one create a copy of the global variable in local scope (instead of adding a reference)?
  • What should happen when a function calls !global &var and &var hasn't been yet set?
@suve
Copy link
Owner Author

suve commented Sep 8, 2018

Partially done in ad7d725. Currently there is no difference between !global $var and !global &var. The construct can be used inside !if and loops to make it consistent with !static.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant