Cind programming language

Language definition Examples Download Contact

Vector

Vector is a finite ordered set of objects. Notation of vector is a list of elements inside brackets ( ... ), separated by a comma characters. (It can be imagine, that each element of the vector is a coordinate from a different space, or it is just another append value to some result.)

Examples:

() (x,y) (-0.05f,7,"c") (1,,3) // missed element means "null", so it is: (1,null,3)

A vector of 1 element is treated as the one element, that it contains.
Therefore, brackets ( ... ) can be freely used to separate language expressions, until there is no comma inside (because otherwise it will be a vector of more then one element).

(x) // x (x,y) // (x,y) (2+2)*2 // 8 (((1+(2)),(4))) // (3,4) (x).hello(()) // x.hello() (x,y)++ // (x++,y++)

And also, vector itself can be handled as an object:

var x = (a,b); // x is a vector of 2 elements

Linear form

When a vector is created, it is always converted to linear form, that is, when some elements are also vectors, then the main vector will be created from its elements (in other words, the vectors will be separated into elements).
Examples:

(()) --> () (1,(2,3),4) --> (1,2,3,4) // second parameter is a vector, so will take its elements (1,(),2) --> (1,2) // adding elements of empty vector, will just remove it (1,,2) --> (1,null,2) // keeping null, because it is not a vector

Notice that arrays, unlike vectors, are not being converted to linear form, and they keeps order of elements and subarrays (see Arrays).

Accessing elements

Once created vector cannot be changed. There are no methods for changing elements of vectors.
Only reading is possible through methods of vector object (see below).

Operators

Operators applied on vectors will be applied to its coordinates (elements), and the result will be a vector of results from coordinates.

(a,b) + (c,d) --> (a+c,b+d) (a,b) + c --> (a+c,b+null) a + (b,c) --> a+b

Operator + in above examples can be changed to any other operator (see Operators).

Methods

Methods accepted by the vector object:

method parameters description result
length () length of vector
get (pos) returns element at given position
subVector (pos,count) returns new subvector starting at given position
toArray () returns new array containing elements from the vector
iterate (fun) iteration - sequential function call for each element in the vector vector of results

Examples of use:

(x,y).length() // = 2, length of vector (a,b,c).get(2) // = c, getting element at position 2 (1,2,3,4).subVector(1,2) // = (2,3), creating subvector, staring at position 1, of length 2 (z,t).toArray() // = [z,t], creating array of vector's elements

Cind programming language 1.0.4