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 installDistThis 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 --versionOn Windows, use gradlew.bat installDist and add build\install\zyn\bin to your Path; it holds a zyn.bat.
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!")Hello, world!
and run it:
zyn run hello.zynzyn 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"))
}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"))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)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 runA 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}!")
}
}$ zyn run main.zyn Ada GraceHello, Ada! Hello, Grace!
args() gives them anywhere, also in scripts. See Command line.
#Three ways to run
| Command | What it does | Good for |
|---|---|---|
zyn run app.zyn | Checks and interprets the program | Trying things, scripts |
zyn build app.zyn | Compiles to app.jar, run with java -jar app.jar | Speed, Java libraries |
zyn build --native app.zyn | Compiles to an executable that needs no Java | Shipping 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
- Basic syntax: the whole language on one page.
- Projects and dependencies: programs with several files and Java libraries.
- Functions, Collections and Null safety for the everyday parts.
examples/tour.zynin the repository uses every feature in one program.