1. Comments
1
|
|
2.Local variables
Local variables start with lowercase letters. They are declared when you first assign them a value.
1 2 |
|
Their type is inferred from their usage, not only from their initializer. In general, they are just value holders associated with the type that the programmer expects them to have according to their location and usage on the program.
For example, reassinging a variable with a different expression makes it have that expression’s type:
1 2 3 4 5 |
|
Underscores are allowed at the beginning of a variable name, but these names are reserved for the compiler, so their use is not recommended (and it also makes the code uglier to read).
3.Global variables
Global variables start with a dollar sign ($). They are declared when you first assign them a value.
1
|
|
Their type is the combined type of all expressions that were assigned to them. Additionally, if you program reads a global variable before it was ever assigned a value it will also have the Nil type.
4.Assignment
Assignment is done with the equal (=) character.
1 2 3 4 5 6 7 8 9 10 11 |
|
Some syntax sugar that contains the = character is available:
1 2 3 4 5 6 7 |
|
A method invocation that ends with = has syntax sugar:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
The = operator syntax sugar is also available to setters and indexers. Note that || and && use the []? method to check for key prescence.
1 2 3 4 5 6 7 8 9 |
|
I will present about control expressions in part 2. Thanks!