Language: Scope
Scope is the context in which variables are created and accessed. If a variable exists in a parent scope, it is accessed and can be modified. Otherwise, the variable is created in your current scope.
Scopes are created with blocks. A block is a possibly empty sequence
of statements within matching brace brackets {}
. You may nest blocks
to create nested scopes.
Package Scope
The package scope is the top level scope within a policy file and encapsulates the entire file contents. Imports, parameters and named functions must be declared within the package scope.
Implicit Scopes
Each any
, all
, and for
statement is considered to be in its own block.
Note that if
statements do not create their own block.
Examples
The example policy below shows various effects of scopes:
a = 1print(a) // 1 f = func() { print(a) // 1 a = 12 b = 1 return undefined}f() print(a) // 12print(b) // undefined