Zyn0.1.0

Zyn

Zyn is a statically typed, general-purpose programming language with a familiar Kotlin-like feel. It runs your programs right away with an interpreter, compiles them to fast JVM jars that can use any Java library, and builds native executables that need no Java at all.

data User(name: String, age: Int)

fn greet(user: User): String = "Hello, {user.name}!"

let users = [User("Ada", 36), User("Linus", 54), User("Grace", 85)]

users
    |> filter { it.age < 60 }
    |> map { greet(it) }
    |> forEach { println(it) }
Output
Hello, Ada!
Hello, Linus!

Every example in these docs is run by Zyn when the site is built, and the output you see under it is what it really printed.

#Where to start

#What Zyn is like

  • Familiar. If you know Kotlin, Java, TypeScript or Swift, you can read Zyn right away: fn, let and var, classes, interfaces and lambdas.
  • Safe. The whole program is type-checked before it runs. Types are inferred, null is only allowed where a type says so (String?), and a match must cover every case.
  • Pleasant. String interpolation with {name}, the pipe operator |>, data types, enums that carry data, errors as values with Result and try, and test blocks built in.
  • Three ways to run. zyn run interprets a program at once. zyn build makes a jar for the JVM, about as fast as Java. zyn build --native makes a standalone executable through C. All three print exactly the same: Zyn's own tests check it.

#A slightly longer example

enum Shape {
    Circle(radius: Float)
    Rect(width: Float, height: Float)
}

fn area(shape: Shape): Float = match shape {
    Circle(r) -> PI * r * r
    Rect(w, h) -> w * h
}

fn parseSize(text: String): Result<Int, String> {
    let n = try text.toInt()
    if n <= 0 { return Err("the size must be positive") }
    return Ok(n)
}

fn main() {
    let shapes = [Circle(1.0), Rect(2.0, 3.0)]
    for shape in shapes {
        println("{shape} has an area of {round(area(shape))}")
    }
    println(parseSize("12"))
    println(parseSize("-3"))
    println(parseSize("twelve"))
}
Output
Circle(radius=1.0) has an area of 3
Rect(width=2.0, height=3.0) has an area of 6
Ok(12)
Err(the size must be positive)
Err('twelve' is not a whole number)

Zyn is young: it is built for fun and for learning, step by step, with Kotlin-level ambitions. Its design notes are in DESIGN.md.