Skip to content
Matthew edited this page Jul 4, 2018 · 6 revisions

Functions are what make things happen in a program. Every executable must have an entry point, main which can be defined as so:

fun void main()
{
}

This is the simplest possible definition of a function in Jet. A more complex function would be this one that adds two numbers and returns the result:

fun int add(int a, int b)
{
    return a + b;
}

The argument declarations are much like that of let statements and consist of a type followed by a variable name.

Lambdas

Functions can also be declared inline in the form of lambdas. These can simply be inline functions or they can capture local values in their scope.

You declare a non-capturing lambdas as follows (the function typename is optional):

// This is a lambda that takes in a char*, and two int arguments then returns void
// The 0 between the [] indicates noncapturing. 
// This allows it to be stored as just a raw function pointer
let void(char*,int,int) fn = [0](char* t, int x, int p)->void
{

};
Clone this wiki locally