I finally started a new implementation of variables and their scope in programming language Mass. My idea is:
- Have local variables
- No need to explicitly declare
- Access available "outside" if necessary
The basic idea is:
- Any variable assignment involves the local level
That is, if I assign
a = 3
in a function, this refers to a local variable in the function. No matter if there is a variable external to the function
See for example
# file variable a = 1 define foo() a = 2 # local variable end foo()
The first variable a is a variable of the file in process (the module). The variable assigned in the foo function is local to that function, and it is different from the outside variable.
But if we do not assign the variable, and only consulted it, its value is returned. example:
# file variable a = 1 define foo() a # access file variable end foo()
In this case, the function foo returns the value to "outside", since this variable has not been assigned in the function when evaluating the return value.
How to edit an "external” variable, that is, a non-local variablel? Well, this is a topic for an upcoming post. The idea: to access the value of a non-local variable, it must be implied, without declaring anything extra. BUT modifying its value must should be explicit: we put something to explicitly declare "we are changing the value of a non-local variable".
Angel “Java” Lopez