The basics


The basics of Kaya programs

A simple Kaya program

As is traditional, the Hello World! program in Kaya.

program hello;

Void main() {
    // My first program!
    putStrLn("Hello world!");

Compile the program by saving the above code as ‘hello.k’ and using kayac hello.k and run it with ./hello – the result should be something like this.

$ kayac hello.k
Compiling program hello
$ ./hello
Hello world!

Even though this is a simple program, it introduces several features of Kaya

  • program hello is the ‘header’ and tells the compiler that this file is a normal program to be compiled to an executable called ‘hello’ (‘hello.exe’ on Windows). Other headers instead make files into library modules or web applications – see later tutorials for more information.
  • All Kaya code (as opposed to data definitions, global variables, etc) must be contained inside a function definition. This short program only has one function, defined by ‘Void main() {‘. This defines a function main, of return type Void (i.e. it returns nothing), with no parameters.
  • In programs, the main function is special – it must always be present and of type Void, and will be run automatically when the program starts. It will therefore call all other functions (directly or indirectly) used by the program.
  • putStrLn is a function defined in the Kaya standard prelude. The standard prelude defines a small set of core functions available to all Kaya programs. Documentation for all functions available in the standard prelude and other Kaya libraries is included in the library reference.
  • // is a comment marker – everything after it on the line is ignored. C-style /* ... */ comments may also be used.

The rest of this tutorial has been split into three parts to keep individual pages short. It is probably best to read them in the order below.

  1. Variables, arrays and data types
  2. Program flow and control
  3. Functions

Recent Comments

No comments to show.