LEVIATHAN vd52e79c4 · d52e79c486

leviathan-lang.com / docs / learn

Hello, Leviathan

Write and run the smallest useful program, and meet the compiler and the build driver.

Your first program

A Leviathan program is a set of declarations plus top-level statements that drive it. The smallest useful program is two lines: an import and a statement. Printing belongs to the io library, and every library reaches a file through an import, so the program first imports console, an ordinary object, and then calls writeln, a real method on it (see Console).

The smallest program

use io::console;

console.writeln("Hello, Leviathan!");
Hello, Leviathan!

Leave the import out and the compiler stops with unknown name 'console', and its note names the line to add: use io::console;. The core language (numbers, strings, arrays, maps, exceptions) needs no import; everything else, the rest of the standard library included, does (see imports).

Running it

Source files use the .lev extension. The compiler binary is leviathan; the build driver you will actually run day to day is trident. To run a file directly through the tree-walk interpreter:

leviathan --run hello.lev        # execute on the oracle interpreter
trident run                      # ...or let trident drive a whole project

Where programs grow

As a program grows you will group code into namespaces and give it an entry point: a function to call, or a file whose top-level statements run. We get there in Shipping a project. For now, top-level statements are all you need.