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.
A first program
Section titled “A first program”Source files end in .lcd. Save this as 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.
Run it
Section titled “Run it”lucid run hello.lcdHello, worldlucid run compiles the file to machine code in memory and runs it at once. Words after the path go to the program:
lucid run todo.lcd add "buy milk"Check it
Section titled “Check it”lucid check reports errors without running anything. It prints nothing when the program is correct.
lucid check hello.lcdA 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.
Test it
Section titled “Test it”Tests live next to the code:
task add(a: int, b: int) -> int return a + b
test "adds numbers" expect add(2, 3) == 5lucid test math.lcdok adds numbers1 tests, 0 failedA failed expect on a comparison shows both sides, such as expect failed: 4 == 5. lucid run skips tests.
Build it
Section titled “Build it”lucid build hello.lcd # writes hello.exe, a standalone programlucid build --target web hello.lcd # writes hello.js, for a browser or NodeNative builds work on Windows x86-64 today. Linux is in progress.
Format it
Section titled “Format it”lucid fmt hello.lcdThere 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.