Quick start
This page takes you from nothing to a compiled, running Yona program.
Install Yona first; you need yonac (the compiler) and yona
(the REPL) on PATH.
Evaluate an expression
Section titled “Evaluate an expression”yonac -e compiles and runs a single expression:
yonac -e 'let fib n = if n <= 1 then n else fib (n-1) + fib (n-2) in fib 10'# => 55Everything in Yona is an expression — a program is one expression, and its
value is the program’s result. let introduces bindings; fib here is a
recursive function bound with function-definition syntax.
Your first file
Section titled “Your first file”Create hello.yona:
# hello.yona — a program is a single expression.import println from Std\IO inprintln "Hello from Yona"What this does, precisely:
import println from Std\IO in …brings one function from the standard library’sStd\IOmodule into scope for the expression that follows.- That expression is the program.
printlnwrites the line; there is no dummy return value and nodowrapper around a single call.
Compile and run:
yonac hello.yona -o hello # default output name is a.out (a.exe on Windows)./hello# Hello from Yonayonac compiles ahead of time: the output is a self-contained native
executable, not a script. Without -o, expression programs compile to
a.out (a.exe on Windows); use --emit-ir if you want to inspect the
generated LLVM IR instead.
Something real: parallel I/O without async
Section titled “Something real: parallel I/O without async”Save as sizes.yona:
# Reads two files concurrently, then reports their combined length.import readFile from Std\File, println from Std\IO, length from Std\String inlet a = readFile "hello.yona", # both reads are submitted b = readFile "sizes.yona" # before either result is neededin println "combined bytes: {(length a + length b)}"Three things to notice:
- No async/await.
readFileperforms non-blocking I/O. Because the two bindings do not depend on each other, the compiler runs them in parallel; the values are awaited automatically at first use (length a). This is Yona’s transparent async — the founding idea of the language. Details in Concurrency. - Multi-binding
let. Oneletintroduces many bindings, separated by commas. Nestingletinsideletis legal but unidiomatic — see Style. - String interpolation.
"{name}"interpolates a variable;"{(expr)}"interpolates an expression (the parentheses are required for anything containing operators).
Pattern matching in ten lines
Section titled “Pattern matching in ten lines”let maybeValue = Some 42 incase maybeValue of Some x -> x * 2 None -> 0end# => 84case matches on the constructors of a value and binds their fields.
Some and None are the constructors of Option, available in every
program without an import. The compiler knows every constructor of a type,
so it can warn when a case does not cover all of them. Your own algebraic
data types are declared with type inside a module — see
Modules. More in Pattern matching
and Types and data.
The REPL
Section titled “The REPL”yonayona compiles and runs each entered expression natively — it is the same
pipeline as yonac, not an interpreter. Useful for exploring the standard
library:
import map from Std\List in map (\x -> x * x) [1, 2, 3]# => [1, 4, 9]Prelude: what needs no import
Section titled “Prelude: what needs no import”These are available in every program without any import: the types
Option a (Some/None), Result a e (Ok/Err), Linear a,
Iterator a, and the functions identity, const, flip, compose.
Everything else — including foldl, map, and filter from
Std\List — lives in Std\… modules; see the
standard library and the prelude reference.
Where to go next
Section titled “Where to go next”- Syntax and evaluation — the exact rules for newlines, literals, and expressions.
- Concurrency —
letvsdovswith, and what the runtime actually does. - Why Yona 2.0 — if you knew the GraalVM-era language.