1. global procedure / function
- Posted by eeel Oct 05, 2015
- 1416 views
using euphoria 3.1
when looking through libraries (for example 'get.e')
i notice that some procedures & function declarations are preceeded with GLOBAL and others are not
can anyone explain to me the difference between PROCEDURE and GLOBAL PROCEDURE?
likewise between FUNCTION and GLOBAL FUNCTION?
i understand how GLOBAL affects a variable decalration - but not a procedure or function declaration
thank you for any information you can share
2. Re: global procedure / function
- Posted by xecronix Oct 05, 2015
- 1414 views
can anyone explain to me the difference between PROCEDURE and GLOBAL PROCEDURE? likewise between FUNCTION and GLOBAL FUNCTION?
That has to do with the scope of a declaration (Variable, Function or Procedure)
- If the keyword global precedes the declaration, the scope of these identifiers extends to the whole application. They can be accessed by code anywhere in the application files.
- If the keyword public precedes the declaration, the scope extends to any file that explicitly includes the file in which the identifier is declared, or to any file that includes a file that in turn public includes the file containing the public declaration.
- If the keyword export precedes the declaration, the scope only extends to any file that directly includes the file in which the identifier is declared.
You can read more about this topic here.
- Official 4.0 documentation
- http://openeuphoria.org/wiki/view/Scope%20Export%20Example.wc
- http://openeuphoria.org/wiki/view/Three%20File%20Scope%20Example.wc
HTH
3. Re: global procedure / function
- Posted by ghaberek (admin) Oct 05, 2015
- 1420 views
using euphoria 3.1
when looking through libraries (for example 'get.e')
i notice that some procedures & function declarations are preceeded with GLOBAL and others are not
can anyone explain to me the difference between PROCEDURE and GLOBAL PROCEDURE?
likewise between FUNCTION and GLOBAL FUNCTION?
i understand how GLOBAL affects a variable decalration - but not a procedure or function declaration
thank you for any information you can share
It basically works the same with variables or routines (functions and procedures). It all has to do with the concept of Scope. (Here is the corresponding doc for 4.0: Scope)
Symbols marked as global can be used externally. All other symbols can only be used internally within their own file. This information is helpful when maintaining or enhancing the file, or when learning how to use the file. You can make changes to the internal routines and variables, without having to examine other files, or notify other users of the include file.
If you include a file that contains routines declared with global, you can call those functions from your file because they are in the global "scope."
Anything that is in another file and not declared as global is effectively hidden from you, and only accessible from within that file, because it is only in the "scope" for that file.
-Greg
4. Re: global procedure / function
- Posted by eeel Oct 08, 2015
- 1327 views
thank you very much - xecronix & greg
i was 'forgetting' the concept that the libraries remain separate files from my program file even when 'included' in my program file - hence the need to use something like 'GLOBAL' before a routine in any these libraries if that routine is to be accessed directly by my program file
now its all clear(er) to me - and very helpful for creating my own libraries of routines
cheerz again