Cind language documentation

Variable preservation

To preserve a variable means, to allow the access to the variable, during future code execution, by the current working processor, including execution in other contexts, where variable may not be visible.
It is like associate a variable with the current processor, by which executed code may access that variable.

Variable preservation declaration syntax consists of the dollar character ( $ ) before the variable name.
Basically writing:

$x;

what means that from this moment a variable x will be preserved.

To access preserved variable in the future code execution, write gravis character ( ` ) before the variable name:

`x

It is allowed by the compiler to use gravis variables without connection to the preserved variables.

The main idea of variable preservation is, that it allows to write the code that will be independent from some variables and even from their declaration, but they are needed in the code, and they may be defined later from any calling context, by a variable preservation technique.

Basic example of variable preservation:

fun() { int y = 9; // variable declaration ... $y; // preservation ... z = `y; // accessing preserved variable ... } // preservation is done, because leaving the context // where variable was preserved

Accessibility

Preservation of a variable starts with preservation instruction and ends with leaving context where variable was preserved, and at that time, the variable may be accessed from any executed code.

Example:

fun f() { // can't use x and y here, but can access them by `x and `y, // because they were preserved before this function was called ... return (`x + `y); } fun g() { // can't use x here, but can access 'x int y = `x + ... ; $y; f(); } fun h() { int x = ... ; // declaration of variable $x; // variable preservation g(); // calling some external function, ... // which may access x by `x } // <-- preservation is done

There is no option to finish variable preservation other then leaving context where variable was preserved.
That context is to the end of the function code or to the end of other code section, but not to the end of a block instruction nor to any other syntax.

Trying access variable which was not preserved will throw an exception.

Preservation with variable declaration

It is possible to preserve variable together with declaration. For example:

int $z = 4;

which is equivalent to:

int z = 4; $z;

Preservation in parameters

It is also possible to preserve variables from parameters. For example:

fun(x,$y) { ... }

it will make preservation of parameter variable y inside function's context.

For more about parameters see Parameters of function.

Functions

Function declaration syntax (lambda notation):

$x.y

makes a function, from variable x, treated as a function parameter, into the code y.
Parameter variable x will be preserved inside the function code y.
This is equivalent with other notations:

$x->y fun($x) { return y; }

It is possible to have more parameters in lambda notation, by puting them in brackets ( ... ).
Example:

$(x,y).z // fun($x,$y) { return z; }

For more about functions see Functions.



Cind programming language 1.0.4

 

Advertisements