Getting started

code-lang is an interpreted language with a clean syntax and a complete standard library. This guide gets you from zero to running your first script.

Install

See the full install guide for step-by-step instructions. The short version — build from source with Cargo:

git clone https://github.com/Walon-Foundation/code-lang
cd code-lang
cargo build --release

Binary lands at target/release/code-lang.

The REPL

Run code-lang (or ./target/release/code-lang) with no arguments to start the interactive shell. History is saved across sessions.

>> let name = "world";
>> "Hello, " + name + "!";
Hello, world!
>> 2 ** 10;
1024
>> exit

Exit with exit, exit(), or Ctrl-C.

Your first script

Scripts use the .cl extension. Create hello.cl:

import "fmt";
import "math";

let greet = fn(name) {
    fmt.print("Hello, " + name + "!");
};

greet("world");
fmt.print("pi ≈", math.PI);

Run it:

code-lang hello.cl
Hello, world!
pi ≈ 3.141592653589793

Importing modules

All standard library modules are built in — no installation or setup needed. Import any module by name and call its functions with dot notation:

import "strings";
import "arrays";
import "json";

strings.to_upper("hello");        # HELLO
arrays.sort([3, 1, 4, 1, 5]);    # [1, 1, 3, 4, 5]
json.stringify({"ok": true});     # {"ok":true}

See the standard library reference for all 12 modules.

Error format

Errors include the source line and a caret pointing to the exact position:

error: identifier not found: foo
 --> 3:9
  |
3 | let x = foo + 1;
  |         ^

Script mode exits with code 1 on any error so you can detect failures in shell scripts.

Next steps

Read the language reference for a complete guide to syntax, types, functions, structs, and modules.