-
Notifications
You must be signed in to change notification settings - Fork 5
Variable Scoping
While cish tries to adhere to the principles of functional programming whenever possible, global function definitions and global variables to simulate states with multiple properties, wouldn't be possible. That being said, conflicting global and local variable names is a potential catalyst for many bugs.
When the compiler sees an identifier, it tries to identify the variable in the following order:
- Is it a local variable?
- Is it a global variable?
If none of the following steps above succeed, an
ERROR_VARIABLE_UNDEF
is invoked.
Note: that all this applies within the current scope (the current procedure declaration). However it should be noted, that unlike many dynamic languages, you cannot access variables declared in a control structure (if, else, elif) from the outside. However it should be noted that control structures can access variables declared before that control structure. For example:
int a = 10;
if(condition) {
a = 20; //this is OK
int b = 30;
}
a = b; //this is NOT OK
int b = 40; //this is OK, and this B is seperate from the one declared in if(condition)
Note: Control structures are things like while loops and if...elif..else blocks. cish uses else if instead of elif. Generally speaking, in any sane language(including cish), you cannot access variables declared outside the current scope, except for globals.
- Getting Started
- The Language and Syntax
- Type Declarations
- Primitive Values
- Collection/Object Values
- Operators
-
The Standard Library
- More docs coming soon after APs.
- FFI and Interoperability
- The Implementation