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
Getting startedInstall Zyn, write a first program and run it.
Basic syntaxThe whole language on one page, for a quick look.
Null safetyHow Zyn keeps null out of places it shouldn't be.
Java interopUse any Java library, extend Java classes, write plugins.
Projectsbuild.zyn, Maven dependencies and runnable jars.
Native programsExecutables for Linux, macOS and Windows, without Java.
Standard libraryEvery built-in function, with its type.
#What Zyn is like
- Familiar. If you know Kotlin, Java, TypeScript or Swift, you can read Zyn right away:
fn,letandvar, classes, interfaces and lambdas. - Safe. The whole program is type-checked before it runs. Types are inferred,
nullis only allowed where a type says so (String?), and amatchmust cover every case. - Pleasant. String interpolation with
{name}, the pipe operator|>,datatypes, enums that carry data, errors as values withResultandtry, andtestblocks built in. - Three ways to run.
zyn runinterprets a program at once.zyn buildmakes a jar for the JVM, about as fast as Java.zyn build --nativemakes 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.