ZPE/YASS has had a global scope since a very early stage in its development. Whilst using global variables is not always very useful, there are times when they are needed.
The ZPE runtime defines a global function (known as globalFunction) that is:
- The parent of all top-level functions in code
- The parent of all global variables
- The owner of all top-level structures
The following code sample demonstrate this:
function main() displayIt() $test1 = 10 displayIt() end function function displayIt() print($test1) end function function getValue() return 2 end function $test1 = getValue()
$test1 variable is defined within the global scope since
it is not defined within any function definition. The
$test1 variable within the global scope, not within their
own scope. This means that the
$test1 variable is changed within the
global scope and not the local scope.
Notice as well, the
$test1 variable is defined after
getValue function. If it were defined before this function, the
runtime would have access to the function and would throw an error.
Everything as a function
The concept of first-class citizens has been available in ZPE/YASS since early days when lambda functions came. As a result, the move to the everything as a function initiative means that ZPE has gained higher performance as well as flexibility.
ZPE/YASS strives to ensure that the globalFunction - encompasing all other functions - allows for the same flexibility as other functions.