Skip to content

kaya-lang/KayaScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

KayaScript banner

The KayaScript Programming Language

Note

KayaScript's development has been going strong since December 2024 - the following examples aren't perfect (yet!). Watch this space to be the first to try KayaScript when its ready for an alpha release!

Welcome to KayaScript

KayaScript is a language that transpiles into other languages. KayaScript can't run on it's own, and you are always automatically detached/ejected from KayaScript after transpilation.

This means it's easy to start using KayaScript to implement your cross platform logic without the risk of tying yourself to a third party ecosystem 🎉

Function<Integer, (Integer n)> fibbonacci = {
    #if n <= 1 {
        #return n
    } #else {
        #return fibbonacci(n = n - 1) + fibbonacci(n = n - 2)
    }
}
Transpiled to Swift
// Generated by KayaScript 0.0.1.
// Do not edit this file directly.

import Foundation

func fibbonacci(n: Int) -> Int {
    if n <= 1 {
        return n
    } else {
        return fibbonacci(n: n - 1) + fibbonacci(n: n - 2)
    }
}
Transpiled to Kotlin
// Generated by KayaScript 0.0.1.
// Do not edit this file directly.

fun fibbonacci(n: Int) : Int {
    if (n <= 1) {
        return n
    } else {
        return fibbonacci(n - 1) + fibbonacci(n - 2)
    }
}
Transpiled to TypeScript
// Generated by KayaScript 0.0.1.
// Do not edit this file directly.

function fibbonacci(n: number): number {
  if (n <= 1) {
    return n
  } else {
    return fibbonacci(n - 1) + fibbonacci(n - 2)
  }
}
Transpiled to Python
# Generated by KayaScript 0.0.1.
# Do not edit this file directly.

from typing import Callable

def fibbonacci(n: int) -> int:
    if n <= 1:
        return n
    else:
        return fibbonacci(n - 1) + fibbonacci(n - 2)

KayaScript won't come with every tool for every scenario. Instead, use it to capture your core business logic and easily delegate behaviour back to your host languages when needed.

// Delegate functionality back to your main implementation
Function<Integer, (Integer x)> sqrt = #external
Function<Integer, (Integer a, Integer b)> mod = #external

// Capture your complex logic for use across multiple platforms
@private
Function<Boolean, (Integer num)> isPrime = {
    #if num <= 1 {
        #return false
    }

    @mutable Integer i = 2
    #while i <= sqrt(x = num) {
        #if mod(a = num, b = i) == 0 {
            #return false
        }
        i = i + 1
    }

    #return true
}

@public
Function<Integer, (Integer n)> findNthPrime = {
    @mutable Integer count = 0
    @mutable Integer num = 2

    #while count < n {
        #if isPrime(num = num) {
            count = count + 1
        }
        num = num + 1
    }

    #return num - 1
}
Transpiled to Swift
// Generated by KayaScript 0.0.1.
// Do not edit this file directly.

import Foundation

private func isPrime(num: Int) -> Bool {
    if num <= 1 {
        return false
    }

    var i: Int = 2
    while i <= sqrt(x: num) {
        if mod(a: num, b: i) == 0 {
            return false
        }

        i = i + 1
    }

    return true
}

public func findNthPrime(n: Int) -> Int {
    var count: Int = 0
    var num: Int = 2

    while count < n {
        if isPrime(num: num) {
            count = count + 1
        }

        num = num + 1
    }

    let result: Int = 0
    return result
}
Transpiled to Kotlin
// Generated by KayaScript 0.0.1.
// Do not edit this file directly.

private fun isPrime(num: Int) : Boolean {
    if (num <= 1) {
        return false
    }

    var i: Int = 2
    while (i <= sqrt(num)) {
        if (mod(num, i) == 0) {
            return false
        }

        i = i + 1
    }

    return true
}

public fun findNthPrime(n: Int) : Int {
    var count: Int = 0
    var num: Int = 2

    while (count < n) {
        if (isPrime(num)) {
            count = count + 1
        }

        num = num + 1
    }

    val result: Int = 0
    return result
}
Transpiled to TypeScript
// Generated by KayaScript 0.0.1.
// Do not edit this file directly.


function isPrime(num: number): boolean {
  if (num <= 1) {
    return false
  }

  let i: number = 2
  while (i <= sqrt(num)) {
    if (mod(num, i) == 0) {
      return false
    }

    i = i + 1
  }

  return true
}

export function findNthPrime(n: number): number {
  let count: number = 0
  let num: number = 2

  while (count < n) {
    if (isPrime(num)) {
      count = count + 1
    }

    num = num + 1
  }

  const result: number = 0
  return result
}
Transpiled to Python
# Generated by KayaScript 0.0.1.
# Do not edit this file directly.

from typing import Callable

def isPrime(num: int) -> bool:
    if num <= 1:
        return False

    i: int = 2
    while i <= sqrt(num):
        if mod(num, i) == 0:
            return False

        i = i + 1

    return True


def findNthPrime(n: int) -> int:
    count: int = 0
    num: int = 2
    while count < n:
        if isPrime(num):
            count = count + 1

        num = num + 1

    result: int = 0
    return result

Features (so far)

Built-in types

Name Purpose
Function<ReturnType, (Arg1Type arg1, Arg2Type arg2)> Function
Integer Integer
Decimal Floating point*
Boolean Boolean
String String
Array<OfType> Array

Note: floating point types can be configured per target language

Keywords

Keyword Purpose
#if expression If statements
#else Else statements
#return expression Function returned values
#while expression Conditional repetition
#cast(value, ToType) Converting between types*
#external Declare a symbol provided by native code; no emission

Note: casting is delegated to the target language (is not handled by KayaScript)_

Annotations

Name Purpose
@mutable Making variables
@private Marking a function as private
@public Marking a function as public

Other

  • Infix operators
  • A VSCode extension with a tmLanguage.json is being maintained alongside the main implementation

Features (to be completed before Alpha)

  • Language server
  • Dictionaries
  • Simple data types
  • Annotation @only(languageId, languageId)
  • Namespaces
  • Inline other languages
    • Annotate function using @only and declare contents of function using a triple-backtick multiline block (like markdown)
  • #elseif

About

The KayaScript programming language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors