Zyn0.1.0

Getting started

This page installs Zyn, runs a first program and shows the three ways of running it.

#Install Zyn

Zyn needs Java 17 or newer (any JDK, 25 included). Get the code and build the zyn command:

git clone https://github.com/Zynvie/zyn-lang.git
cd zyn-lang
./gradlew installDist

This puts the zyn command in build/install/zyn/bin. Add that folder to your PATH so you can type zyn anywhere:

export PATH="$PWD/build/install/zyn/bin:$PATH"   # in ~/.bashrc or ~/.zshrc to keep it
zyn --version

On Windows, use gradlew.bat installDist and add build\install\zyn\bin to your Path; it holds a zyn.bat.

Tip

After pulling a newer version of Zyn, run ./gradlew installDist again to update the zyn command.

#Your first program

Make a file called hello.zyn:

println("Hello, world!")
Output
Hello, world!

and run it:

zyn run hello.zyn

zyn hello.zyn does the same. There's nothing to compile first: zyn run checks the whole program for mistakes, then runs it.

#Scripts and main

A file can be a script, with code at the top level that runs from top to bottom, like the program above. Bigger programs have a main function instead, which runs after the file's declarations are set up:

let greeting = "Hello"

fn greet(name: String): String = "{greeting}, {name}!"

fn main() {
    println(greet("Zyn"))
}
Output
Hello, Zyn!

A file with fn main() can only declare things at the top level (fn, let, var, types and test blocks): loose statements like println(...) must go in main.

#Mistakes are found before running

Zyn checks the types of the whole program before running any of it, and shows where the mistake is:

fn double(x: Int): Int = x * 2

println(double("four"))
Error
Type error: Argument 'x' of 'double' must be Int, but got String
  --> main.zyn:3:16
  |
3 | println(double("four"))
  |                ^

It also suggests what you might have meant:

let count = 3
println(cuont)
Error
Type error: Unknown variable 'cuont'. Did you mean 'count'?
  --> main.zyn:2:9
  |
2 | println(cuont)
  |         ^

#Projects

When a program grows into several files or needs libraries, make it a project:

zyn init my-app
cd my-app
zyn run

A project has a build.zyn listing its libraries, which Zyn downloads from Maven repositories. See Projects and dependencies.

#Command-line arguments

What comes after the file goes to the program. main can take the arguments as a List<String>:

fn main(args: List<String>) {
    for name in args {
        println("Hello, {name}!")
    }
}
Output$ zyn run main.zyn Ada Grace
Hello, Ada!
Hello, Grace!

args() gives them anywhere, also in scripts. See Command line.

#Three ways to run

CommandWhat it doesGood for
zyn run app.zynChecks and interprets the programTrying things, scripts
zyn build app.zynCompiles to app.jar, run with java -jar app.jarSpeed, Java libraries
zyn build --native app.zynCompiles to an executable that needs no JavaShipping small, fast tools

They print exactly the same thing for the same program. zyn run --jvm and zyn run --native compile and run in one step.

#The REPL

zyn repl lets you type Zyn and see results at once. Each line can use what the earlier lines defined:

$ zyn repl
Zyn 0.1.0. Type :help for help, :quit to leave.
zyn> let xs = [3, 1, 2]
zyn> xs.sorted()
[1, 2, 3]
zyn> fn square(x: Int): Int = x * x
zyn> square(12)
144

#Editors

Zyn has a language server, so editors show errors as you type, types on hover, go to definition and completion. There's an extension for VS Code and a plugin for IntelliJ IDEA: see Editors and tools.

#Next steps