Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/elfrask/cls/llms.txt

Use this file to discover all available pages before exploring further.

This guide takes you from an empty directory to a running CLS program. You will scaffold a project with clx new, inspect the generated files, execute your first script, run the static type checker, and produce a packaged application — all in a few short commands. Make sure you have clx on your PATH before continuing (see Installation if you haven’t built it yet).
1

Create a new project

Use clx new to scaffold a project directory with a manifest and a starter source file:
clx new my-app
cd my-app
clx new generates two files:cls.json — the project manifest:
{
  "name": "my-app",
  "version": "0.1.0",
  "entry": "src/main.clsx",
  "compiler": {
    "targetArchitecture": "wasm",
    "optimizationLevel": "O2"
  },
  "interpreter": {
    "sandbox": {
      "allowFs": false,
      "allowNet": false
    }
  },
  "dependencies": {}
}
src/main.clsx — the entry-point source file:
function main(args: String[]) -> int {
    print("Hello, World!");
    return 0;
};
The entry field in cls.json points to this file. clx run (with no arguments) reads cls.json to know where to start.
2

Run the project

Execute the project directly from its root directory:
clx run
Output:
Hello, World!
You can also target a specific source file explicitly:
clx run src/main.clsx
To pass command-line arguments to your script, append them after --:
clx run src/main.clsx -- arg1 arg2
Inside the script, args contains each value as a String:
function main(args: String[]) -> int {
    print("First argument:", args[0]);
    print("Second argument:", args[1]);
    return 0;
};
3

Check types

Run the static type checker without executing the program:
clx check
To target a specific file or enable strict mode (which enforces all type annotations):
clx check --strict src/main.clsx
If no errors are found, the checker reports success. Any type mismatches, unresolved names, or missing annotations in strict mode are reported with file, line, and column information before your code ever runs.
4

Build a packaged application

Bundle the project into a self-contained .clsapp file that clxr can execute without the full development toolchain:
clx build
This produces dist/app.clsapp — a zip archive containing the source files and resolved modules. Run it anywhere you have clxr:
clxr dist/app.clsapp

Hello World in Detail

The entry point for every CLS program is the main function. It receives the command-line arguments as an array of strings and must return an integer exit code:
function main(args: String[]) -> int {
    print("Hello, World!");
    return 0;
};
CLS uses semicolons to terminate statements and to close block declarations. A plain statement ends with ;. A block-opening declaration (function, if, while, class, structure, etc.) closes its curly-brace block with };. This is intentional and consistent across the entire language.

Variables, Functions, and String Interpolation

Here is a slightly more involved example that demonstrates variable declarations, a helper function, and CLS string interpolation:
function greet(name: String) -> String {
    return "Hello, $name!";
};

function add(a: int, b: int) -> int {
    return a + b;
};

function main(args: String[]) -> int {
    var language: String = "CLS";
    const version = 2;

    print(greet(language));

    var x = 10;
    var y = 32;
    var result = add(x, y);
    print("${x} + ${y} = $result");
    print("Running version $version");

    return 0;
};
Output:
Hello, CLS!
10 + 32 = 42
Running version 2
A few things to notice:
  • var declares a mutable variable; const declares an immutable binding.
  • Type annotations (name: String, a: int) are optional but recommended — clx check --strict enforces them.
  • String interpolation uses $name for simple identifiers and ${expression} for any expression.
  • Functions are declared with function, a parameter list, an optional -> ReturnType arrow, and a body closed by };.

Async Example

CLS has first-class async/await support. Async functions are declared with the async keyword and can await any async expression:
async function fetchData(url: String) -> String {
    var result = await http.get(url);
    return result;
};

function main(args: String[]) -> int {
    var data = await fetchData("https://api.example.com/data");
    print("Response:", data);
    return 0;
};

Next Steps

Language Syntax

The complete syntax reference — control flow, data structures, classes, interfaces, CMX markup, error handling, and the import system.

Type System

Primitive types, generic collections, union types, type aliases, and how the static checker enforces them.

clx CLI Reference

Every clx subcommand with all flags — run, check, build, maptype, ast, repl, lsp, and the package manager commands.

cls.json Config

Full schema reference for the project manifest — compiler targets, optimization levels, sandbox policies, and dependency management.

Build docs developers (and LLMs) love