Cind language documentation

Creating objects

A data managed by the Cind program consists of objects.
There are five kinds of objects, that can be created: system objects, arrays, objects of classes, vectors, and functions.
External objects cannot be created explicitly.

System objects, vectors and functions

One way to create value of system type is to write it directly in the code.
For example:

int x = 7;

creates object of value 7, of system type int and stores it in variable x.

For notation and syntax of values of system types see Data types.

Another way of creating system objects is to obtain it as a result of operations (e.g. from arithmetic instruction), type conversion or from the result of some code execution.

A vector can be created by indicating its elements (see Vector of values).

A function object is created in the place of its definition (see Functions).

Arrays

Array can be created directly by indicating elements in the brackets [ ... ], separated by the commas, or by using instruction new.
Examples:

x = [a,b,c,d] y = new int[10]; z = new a.b.c[][][5][5];

For more about arrays see Arrays.

Objects of classes

Objects of classes can be created where a class definition is accessible (see Classes).
For example:

class c { ... } ... x = new c(...);

it creates one new object of class c and saves it to variable x.

Vector of values given after the name of a class is a vector of parameters passed to the constructor of the object.
For more about classes see Classes.

It is also possible to create an object without separate class definition,
by writing class definition after instruction new.
Example:

x = new { .print() { host.println("Hello from object of unnamed class!"); } ... };

In the same way, it is allowed to create an objects, whose classes extends from the other class (see Class inheritance).
For example:

x = new a.b.c { .f() { ... }; ... };

it creates object of class, which extends from the a.b.c class.

To create object that will be over another one in inheritance chain, use:

x = new over y { ... };

The word over can be omitted, which allows to create a chain of objects:

x = new y { ... }; // --> new over y { ... } x = new y { ... } { ... }; // --> new over (new over y { ... }) { ... }

And the last point, to create an array of objects of the same class, put the length of array at the end:

x = new { ... }[8];

That will create array of 8 objects of given class (that will not be an empty array, but 8 different objects will be created).

Variants of instruction new

Putting together all the variants of the instruction new, there is:

x = new { .hello { return true; } } // new object of given class (without word: class) x = new { .a{} z:2 } [10]; // table of 10 different objects, but of the same class x = new extends a.b { ... } // new object which class extends from a.b x = new a.b { ... } // as above, without word: extends x = new over y { ... } // object y will be connected to the new object as "under" in inheritance chain x = new y { ... } // when y is an object, than a hidden word "over" is there x = new selector { ... } // new object of selector class x = new selector over y { ... } x = new monitor { ... } // new object of monitor class x = new a.b(p1,p2); // new object of class a.b with parameters passed to the constructor x = new a.b[5]; // array 0..4 of nulls, which can store object of class a.b x = new int[10][10]; // 2 dimensional array of ints x = new static { ... } // new object of static class x = new a.b monitor { ... } // --> new monitor extends a.b { ... } x = new a.b(p) monitor { ... } // --> new monitor over (new a.b(p)) { ... } x = new a.b static monitor { ... } // --> new static monitor extends a.b { ... } x = new a.b(p) static monitor { ... } // --> new static monitor over (new a.b(p)) { ... } // -- notice that class a.b and value p must be in static context x = new int[3]; // array of 3 ints x = new int[3] { ... } // --> new over (new int[3]) { ... } x = new int[3] { ... } { ... } // --> new over (new over (new int[3]) { ... }) { ... } x = new int[3] { ... } [4]; // --> new over (new int[3]) { ... } [4] -- it creates 4 objects and 1 array x = new int[3] { ... } [4] { ... } // --> new over (new over (new int[3]) { ... } [4]) { ... } x = new int[2]; // array of 2 ints x = new int[][2]; // array of 2 items of type int[], initially has nulls x = new int[3][2]; // 2 dimensional array of ints x = new int[][3][2]; // 2 dimensional array of items of type int[] x = new int[4][3][2]; // array[0..1] of array[0..2] of array[0..3] of ints x = new int[][][2]; // array[0..1] of nulls (of type int[][])



Cind programming language 1.0.4

 

Advertisements