Next: , Previous: Basics, Up: Syntax

3.1.2 Declarations Required Version

A module can specify the minimum required version in order to run. This can be done by using the version keyword, as shown below:

     version "1.2.0";
     "hello world"|print;

If a user attempts to run the above code on a version of Kite lower than 1.2.0, an exception will be thrown. The minimum supported version that can be specified here is 1.0.0. Only two of the version components are required–the third one will default to being 0 if not specified:

     version "1.2";
     "hello world"|print; Classes

The class is the fundamental unit in Kite. All objects, whether built-in or user-created, are instances of classes. To declare a class, use the class keyword:

     class Hello from System.object [

The from System.object is optional, as all classes inherit from System.object by default. If specified, your class will inherit from the class specified. This allows for single inheritance:

     class Greetings [
     class Hello from Greetings [

All declarations inside of a class are delimited by commas, instead of semicolons. Properties/variables

Properties and variables are the same in Kite. To declare, use the property keyword:

     class Greeting [
         property text,
         global property number_given
     property desired;

global is an optional keyword that goes before property that indicates that the property is to be shared amongst all instances of the class. This is equivalent to static members in C++ and similar languages.

Properties can also have a value assigned to them on first creation, as seen here:

     class Greeting [
         property text = "Hello!",
         global property number_given = 1
     ]; Methods

Methods work in a similar way as in other languages, and are declared using the method keyword:

     class Hello from Greeting [
         method sendGreeting(string) [
     method greetings() [
         (make Hello())|sendGreeting("hello");

Unlike in other languages, there is no concept of static vs. instance methods; however, this will be null inside of methods called without an instance and not called inside of a class. Methods can take any number of parameters, and method overloading is possible:

     class Hello from Greeting [
         method sendGreeting() [
         method sendGreeting(greeting) [

The return value of any method is the return value of the last executed statement in the method. In the example above, sendGreeting() will return whatever print returns.

Anonymous methods are also possible, by removing the method name from the declaration. Example:

     x = method(a) [
         (a + 1);

Any references to variables/properties inside a method call will search for the property down the call stack. That is, x inside the method will change the declaration outside the method unless a property declaration is included:

     property x;
     method y() [
         x = 3;
     x = 2;

To exit out of a method early, simply use the return keyword:

     method x(y)
         "should not reach here"|print;
     x(1); Operators

Kite also supports operator overloading using the operator keyword. Overloadable operators are below:

Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
Modulus (%)
Unary plus (+)
Unary minus (-)
Map (<-)
Reduce (<|)
Array dereference ([])
Less than (<)
Greater than (>)
Less than or equal to (<=)
Greater than or equal to (>=)
Logical/bitwise AND (and)
Logical/bitwise OR (or)
Logical/bitwise NOT (not)
Logical/bitwise XOR (xor)
Left shift (<<)
Right shift (>>)
Method call. Caution: the array passed in as the argument contains the method name for the first element (as a string) and a list containing the arguments as the second element. This operator is also called only if said method does not exist.

All operator methods above only take a single argument, the right hand side of the operation (if any). For the unary operators, this argument will be null. The left hand side is always this. Example:

     class Widget [
         property number,
         operator add(rhs) [
             property ret;
             ret = make Widget;
             ret.number = this.number + rhs.number;
     ]; Constructors and Destructors

Constructors and destructors are created using the construct and destruct keywords:

     construct (param1, param2, ...) [
     destruct [

Constructors can also be overloaded, as appropriate. To call a base class's constructor, use base|__construct__(...) (base also works in any class method to call parent's version of said method). Any return value from the constructor is ignored. Package importation

Packages are imported using the import keyword, with the name of the package in quotes:

     import "System.vm.thread";

Each component of the package is separated by a period and corresponds to an element of the path (see Extending Kite for more information).

Caution: import instructions are executed before any other code is run. This can interfere with proper operation if the package you're looking for is not in the standard Kite lookup path. Use eval (see Dynamic code evaluation) as a workaround.