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

global doesn't work for functions as mentioned in the documentation #1831

Closed
SchwarzChristian opened this issue Oct 6, 2016 · 4 comments · Fixed by #1834
Closed

global doesn't work for functions as mentioned in the documentation #1831

SchwarzChristian opened this issue Oct 6, 2016 · 4 comments · Fixed by #1834
Assignees
Labels
documentation Change the Sphinx user documents.

Comments

@SchwarzChristian
Copy link

The documentation says "The DECLARE, FUNCTION, and LOCK commands can be given explicit GLOBAL or LOCAL keywords to define their intended scoping level[.]", but if i try

{
  global function hello {
    print "Hello, World!".
  }.
}

hello().

kOS says

run test.
Program ended.
  global function hello {
    print "Hello, World!".
  ^
line 2, col 3: 'GLOBAL' command found in a function declaration. It only works in a variable declaration.
At interpreter, line 18
run test.
    ^

local works fine.

Seems like an error in the documantation, but having global functions would be nice ;)

@Dunbaratu Dunbaratu added the documentation Change the Sphinx user documents. label Oct 6, 2016
@Dunbaratu
Copy link
Member

The documentation should be fixed. But having global functions already is possible. Just not by declaring global scope from inside local scope.
If you want to do that, you can assign a local function delgate to a global name:

{
  function aaa { print "aaa". }
  global bbb is aaa@.
}
bbb().

@SchwarzChristian
Copy link
Author

Sure, or for short, you can declare the function as a delegate directly.
global hello is { print "World!". }.

A global function would certainly be more descriptive, but the workaround is ok.

Btw., thanks for the great mod!

@Dunbaratu
Copy link
Member

Well, the other question that immediately comes up is ... if you wanted the function to be global why not just declare it outside the scoping braces and then you don't need to mess with delegates.

@SchwarzChristian
Copy link
Author

Encapsulation. I have a library that needs local state and i don't want to publish it. But to access the local state from the libraries functions, they need to be in the same scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Change the Sphinx user documents.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants