Kotlin

Kotlin/Native

Installation

Arch Linux
pacman -S kotlin
Binary
# Download kotlin-native-{os}-{arch}-{version}.tar.gz from https://github.com/JetBrains/kotlin/releases
tar xzf kotlin-native-{os}-{arch}-{version}.tar.gz
mv xzf kotlin-native-{os}-{arch}-{version} /usr/local/kotlin-native
export PATH=/usr/local/kotlin-native/bin:$PATH

Examples

Fibonacci Numbers
// Fibonacci Numbers
fun fib(n: Int) : Int {
    return if (n < 2)
        n
    else
        fib(n - 2) + fib(n - 1)
}

fun main(args: Array<String>) {

    val n:Int = args[0].toInt()
    println(fib(n))
}

/*
    example
        native code
            compile:
                kotlinc-native fib.kt -o fib
            run:
                ./fib.kexe 39
        byte code
            compile:
                kotlinc fib.kt -include-runtime -d fib.jar
            run:
                kotlin fib.jar 39
*/