-
Notifications
You must be signed in to change notification settings - Fork 26
Scopes
Imagine a syntax this:
def gx = 30
{
def x = 10
{
def y = x * 10
}
}
In the above, there are three scopes being defined:
- First is the global scope. In this scope gx is being defined. It will be visible throughout the scope of the application.
- The second level scope is the one defined by the outermost braces
{
and}
. In this scopex
is being defined and it will be visible only it this scope and nested scopes. However it will not be visible in the global scope. - The third level scope is defined by the innermost braces. In this
y
is being defined and accessesx
in its definition.
The benefit of scopes is that they make it easier to reason about the system. The visibility and effect of variables or directives can be limited.
For example, if there were to be a directive for an auto account, its effect could be restricted with scopes:
{
auto account Cash;
2013/4/1
Expense 100
2013/5/1
Expense:Food 200
}
The directive for auto account is now restricted to the scope and doesn't have a global effect.
I am not convinced yet that the following ideas would be good to implement.
-
Instead of a single global scope, there could one scope per file. The global scope would have to be explicitly accessed using a
global
keyword. -
What happens if a file is included from another file. Do the scopes from the included file get nested at the point where the inclusion happens?