SOUL (formerly User Language) entities such as variables, complex subroutines, classes, and methods have what is referred to as a scope. The term scope refers to two things:
- The scope in which an entity is declared or defined
- The scope in which an entity can be referenced
In general, there are two scopes in SOUL:
- The outermost scope; specifically the scope directly inside the Begin/End block and not inside a complex subroutine or method.
- A method or complex subroutine scope.
Only one entity of a particular type (variable, method, class, etc.) and name can be defined within a scope. For example, the following is 'not allowed:
begin %x is float %x is string len 8 %x = 'Hello' end
Similarly, the following is also invalid:
local subroutine (string):silly %x is float %x is string len 8 %x = 13 end subroutine
Hopefully, the reasons for this restriction are obvious.
It is perfectly valid, however, for like entities to be defined or declared with the same names in different scopes. For example, the following is perfectly valid:
begin %x is float local subroutine (string):silly %x is float %x = 13 end subroutine %x = 'Hello' end
Variable names always begin with a percent (%) symbol and must be either explicitly or implicitly declared within the outermost (Begin/End) or method/complex subroutine scope. Explicit declaration is accomplished by starting a line with the name of the variable, optionally followed by the word Is, followed by the type of the variable (Float, String, Object, etc.), as in:
%foo is float %bar object stringlist
Variables are declared implicitly the first time they are referenced within a scope. Implicitly declared variables will always have the same type (as indicated by the Model 204 VTYPE user parameter). If VTYPE is set to UNDEFINED or the request has a VARIABLES ARE UNDEFINED compiler directive, no implicit declarations will be done. In any case, once a variable is declared inside a scope, the name can be used anywhere else inside the scope to reference the variable. That variable will not be available outside the declaring scope.
Model 204 images and screens can also be though of as variables though their declaration is different from a variable declaration. As such, an image or screen declared with a scope can only be referenced in that scope.