Next: , Previous: Declarations, Up: Syntax


3.1.3 Object creation

3.1.3.1 Explicit creation

Objects are created using the make keyword:

     var = make Class(param1, param2, ...);

make returns the object itself, which can be used in method calls. The parameters passed into make will be passed to the constructor.

Please note: As of 1.0a2, parent class constructors are not called (but any constructors in the given class matching the number of parameters are). Constructors that need to call parent constructors can use parent|__construct__(...), where parent is the name of one of the parent classes.

3.1.3.2 Implicit creation

Objects are implicitly created when operators are run upon them (for instance, adding two numbers). The supported operators are listed under the Operators section above.

3.1.3.3 Map/Reduce

Kite has built-in support for the map and reduce operators (<- and <|, respectively). Map applies a method to each element of an object (by default, any object that implements the iterator methods), while reduce constructs a single new object from another object using a method. For example:

     method mapping(a) [
         (a + 1);
     ];
     method reducing(a, b) [
         (a + b);
     ];
     
     ([1,2,3]<-mapping)|print;
     ([1,2,3]<|reducing)|print;

which outputs:

     [2,3,4]
     6