Next: Method calls and dereferencing, Previous: Declarations, Up: Syntax
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.
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.
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.
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