Skip to content

Getting Started

DatAsiqn edited this page Nov 2, 2026 · 3 revisions

Setup

To get started using Lantern, clone the repository and install the cli. More details can be found in the README.

Double-check that Lantern is installed by running lantern --version:

$ lantern --version
lantern 0.1.0

Moving forward, this guide assumes you have copied examples/std.la into the root folder of your Lantern file(s). Eventually, packages will allow you to automatically import these files into any project.

Hello, World!

First, create a new file. It can be named anything, but make sure it ends with .la (technically the program can still run without a Lantern file extension, but it becomes more important when working with modules). In this example, the file is called main.la.

In that newly created file, write the following:

using std{};

fun main() {
  println("Hello, World!");
}

and run the file:

$ lantern main.la
...
Hello, World!

Congratulations! You have successfully written a simple Hello, World program.

If you've worked with other languages before, much of this syntax will look familiar. Regardless, let's dissect this simple program.

The very first line is importing all items from the std module. This will be explained more later, but for now just understand that it's allowing our program to use all items from std.la.

Next, we define a function called main using the fun keyword. This will be the entrypoint for our program, and it tells Lantern what code to execute when running the program. This function must be named main, otherwise Lantern will not be able to find it. Try deleting the function and see what happens:

using std{};
$ lantern main.la
error: no entrypoint defined
  in main.la:1:1:

  using std{};
  ^ no entrypoint defined

We get an error because Lantern cannot find an entrypoint, and execution gets aborted. Now, add the function back and rerun the program to make sure everything works prooperly.

using std{};

fun main() {
  println("Hello, World!");
}

Taking a closer look at the function definition, it uses the fun keyword, a name, and a list of parameters. In this case, the name of our function is main and it takes no parameters. If there were parameters, they would go inside the parentheses (). We begin the function body with a pair of brackets {}. These brackets must contain all statements that the function will execute, which in this case is a single line.

Looking into the function body itself, you will see what's called a function call: an identifier (name) followed by parentheses. We call the println function and pass a string argument, "Hello, World!". Finally, the expression is ended with a semicolon. In Lantern, most statements must end with a semicolon (similar to other C-like languages).

The println function takes in the string argument and writes that string into the standard output, which you see in your console output.

Extras

The lantern cli has some extra arguments you can pass through, most notably --print-ast and --print-codegen. Try running these with your Lantern file and see what you get!

Clone this wiki locally