Skip to content

Getting started

Lucid is a general-purpose, compiled language that reads like plain English. Programs compile to native code through Cranelift, or to WebAssembly for the browser. Ownership is inferred, so you write no lifetimes, and there is no garbage collector.

Source files end in .lcd. Save this as hello.lcd:

hello.lcd
task greet(name: text) -> text
return "Hello, {name}"
print greet("world")

A task is a function. Its parameters and return type are always written out. Blocks are indented by four spaces, and {name} inside text inserts a value.

Terminal window
lucid run hello.lcd
Hello, world

lucid run compiles the file to machine code in memory and runs it at once. Words after the path go to the program:

Terminal window
lucid run todo.lcd add "buy milk"

lucid check reports errors without running anything. It prints nothing when the program is correct.

Terminal window
lucid check hello.lcd

A mistake gets a stable code, a position, and often a fix:

typo.lcd:2:7: error E0301: name `totl` is not defined
fix: rename to `total`

lucid fix typo.lcd applies that fix, and lucid explain E0301 explains the code. Add --json to any of these to get the same thing as data.

Tests live next to the code:

math.lcd
task add(a: int, b: int) -> int
return a + b
test "adds numbers"
expect add(2, 3) == 5
Terminal window
lucid test math.lcd
ok adds numbers
1 tests, 0 failed

A failed expect on a comparison shows both sides, such as expect failed: 4 == 5. lucid run skips tests.

Terminal window
lucid build hello.lcd # writes hello.exe, a standalone program
lucid build --target web hello.lcd # writes hello.js, for a browser or Node

Native builds work on Windows x86-64 today. Linux is in progress.

Terminal window
lucid fmt hello.lcd

There is one layout and no settings, so formatting never comes up in review.

Read the language pages in order, starting with Syntax. The whole reference is small enough to read in one sitting.