henry-luo/lambda

A modern, general-purpose, pure functional programming language (Alpha)

C++

14

7,449 commits

updated Oct 1, 2026

See the code

See what people are saying

README

Lambda Script

License: MIT Platform C++17 Runtime: 20 MB HTML5: 100% CommonMark: 100% YAML 1.2: 100%

A general-purpose, cross-platform, functional scripting language and document processing engine in a single ~20 MB executable, built from scratch in C/C++.

Lambda is designed for two things at once:

  1. an expressive functional language for transforming data and documents, and
  2. an end-to-end document pipeline (parse → validate/transform → layout → render/view).

Lambda and Radiant document pipeline

Internally, Lambda treats documents as structured data. Different input formats (Markdown, Wiki, HTML/XML, JSON/YAML/TOML/CSV, LaTeX, PDF, …) are parsed into a unified Lambda/Mark node tree, transformed with Lambda scripts, validated with schemas, and then rendered via the Radiant HTML/CSS/SVG/JS layout engine.

Note: Lambda Script is still evolving — syntax/semantics and implementation details may change. A stable subset of the literal data model is separately formalised and released as Mark Notation.

Demo

See all supported document types in the demo gallery.

Try it: download the Lambda binary from the Releases page, unzip, and run:

lambda demo

Features

Lambda script (pure functional runtime)

  • Pure-functional core with immutable data structures (arrays, maps, elements) and first-class functions and types.
  • Expressive pipe operator (|>, with the filter stage |:) for fluent set-oriented data transformation pipelines with inline mapping and filtering.
  • Vector arithmetic with automatic broadcasting — apply scalar operations to entire collections.
  • Powerful for-expressions with where, order by, limit, offset clauses for SQL-like data querying.
  • Interactive REPL for exploration and debugging.

Markup input parsing & formatting

  • Multi-format parsing: JSON, XML, HTML, Markdown, Wiki, YAML/TOML/INI, CSV, LaTeX, PDF, and more.
  • One universal representation: parse disparate syntaxes into a common Lambda/Mark node tree.
  • Conversion pipeline: convert between formats using lambda convert (auto-detect input formats when possible).
  • DOM-centric tooling: designed to treat "documents as data/objects", not just as text.

Type system & schema validation

  • Rich type system with type inference and explicit type annotations, similar to and beyond that of TypeScript.
  • Schema-based validation for structured data and document trees (including element schemas for HTML/XML-like structures).

Type Hierarchy

Radiant HTML/CSS/SVG/JS layout, rendering & viewer

  • Browser-compatible layout engine supporting html block, inline, flex, grid, and tables.
  • Unified interactive viewer via lambda view:
    • HTML/CSS/SVG with JavaScript — the embedded LambdaJS engine covers ES2024 (test262), the browser DOM and a Node.js compatibility layer
    • XML (treated as HTML with CSS styling)
    • Markdown / Wiki (rendered with styling)
    • LaTeX (.tex) via conversion to HTML
    • Lambda script (.ls) evaluated to HTML and rendered (think of PHP)
  • Render targets: SVG / PDF / PNG / JPEG output via lambda render.

Language Highlights

Elements (Markup Literals)

First-class markup syntax for document generation:

let card = <div class: "card",
    <h2 "Title">
    <p "Content here.">
>
format(card, 'html')

Vector Arithmetic

Scalar operations automatically broadcast over collections:

1 + [2, 3];          // [3, 4]       — scalar + array
[1, 2] * 2;          // [2, 4]       — array * scalar
[1, 2] + [3, 4];     // [4, 6]       — element-wise
[1, 2] ** 2;         // [1, 4]       — element-wise power
[1, 2, 3] eq 2       // [false, true, false] — element-wise comparison

Pipe Operator & Data Pipelines

The pipe operator |> enables fluent data transformations, and its filter stage |: keeps the items a test accepts. Use ~ to reference the current item:

let users = [{name: "Alice", age: 30}, {name: "Bob", age: 15}, {name: "Carol", age: 41}]

// Map: double each element
[1, 2, 3] |> ~ * 2;                  // [2, 4, 6]

// Extract fields
users |> ~.name;                     // ["Alice", "Bob", "Carol"]

// Filter with '|:'
[1, 2, 3, 4, 5] |: ~ > 3;            // [4, 5]

// Chain operations: filter → map → aggregate
users |: ~.age >= 18 |> ~.name |> len   // 2 — count adult names

For-Expressions with SQL-like Clauses

Powerful comprehensions with let, where, order by,group by, limit, offset:

// Filter and transform
for (x in data where x > 0) x * 2

// With local bindings
for (x in data, let sq = x * x where sq > 10) sq

// Sorting and pagination
for (x in items order by x.price desc limit 5) x.name

Rich Type System

// Type annotations
let x: int = 42
let items: string[] = ["a", "b"]

// Union and optional types
type Result = int | error
type Name = string?

// Element type patterns
type Link = <a href: string; string>
type Article = <article title: string; string, Section*>

// Function types
fn add(a: int, b: int) int => a + b

Pattern-based Matching & Query

Match expressions support value, range, type, and constrained patterns:

fn describe(x) => match x {
    case null:             "nothing"
    case 0:                "zero"              // literal value
    case 1 to 9:           "small number"      // range
    case int that ~ > 9:   "big number"        // type + constraint
    case string:           "text: " ++ ~       // type
    case int[]:            "int array"         // collection type
    default:               "something else"
}

The ? query operator searches data trees by type or structure, similar to jQuery:

html?<img>                    // all <img> descendants
html?<div class: string>      // <div>s with a class attribute
data?{status: "ok"}           // maps where status == "ok"
html[body][div]?<a>           // direct path then recursive search (given type body = <body>, type div = <div>)

Quick Start

Install From Source

  1. Clone the repository:

    git clone https://github.com/henry-luo/lambda.git
    cd lambda
    
  2. Install dependencies:

    ./setup-mac-deps.sh       # macOS
    ./setup-linux-deps.sh     # Linux
    ./setup-windows-deps.sh   # Windows (under MSYS2)
    
  3. Build:

Lambda uses a Premake5-based build system generated from build_lambda_config.json.

make build             # Incremental build (recommended)
make release           # Optimized release build
make test              # Run unit test
make clean-all         # Clean build artifacts

CLI Commands

The build produces lambda.exe at the repo root; release bundles ship it as lambda.

lambda                                          # interactive REPL
lambda <script.ls>                              # run a functional script
lambda run <script.ls>                          # run a procedural script
lambda validate <file> [-s <schema.ls>]         # validate against a schema
lambda convert <input> -t <to> -o <output>      # format conversion
lambda layout <file.html>                       # print the CSS layout tree
lambda render <input> -o <output.svg|pdf|png>   # render to image
lambda view <file.html|file.md|file.ls|...>     # open in interactive viewer
lambda edit <file.md|file.html|file.svg>        # edit a document and save it back
lambda fetch <url> [-o file]                    # download a URL
lambda js <script.js>                           # run JavaScript on LambdaJS
lambda --help                                   # show help

Tip: lambda <command> --help prints detailed options and examples.

Examples

Document Processing

// Parse JSON and convert to Markdown (`^` propagates a read error)
let data = input("data.json", 'json')^
format(data, 'markdown')

// Process CSV data
let csv = input("data.csv", 'csv')^
for (row in csv where row.age > 25) row

Interactive CLI/REPL

λ> let data = input("sample.json", 'json')^
λ> len(data.users)
42
λ> for (u in data.users where u.active) u.name
("Alice", "Bob", "Charlie")

Benchmark Results

Lambda benchmark history

The latest run (Result50, 2026-09-30) covers 63 benchmarks across six standard suites (R7RS, AWFY, BENG, KOSTYA, LARCENY, JetStream) plus Text, against Node.js v22.13.0. Ratios are geometric means of JIT-pinned Lambda execution time divided by Node.js time; below 1.0× means Lambda is faster.

Lambda MIR JIT vs. Node.jsGeo. Mean RatioLambda WinsTotal
Typed0.54× (1.8× faster)4263
Untyped1.05× (5% slower)3263

See the latest full benchmark report for per-benchmark details, memory profiling, and cross-engine comparisons.

Standards Conformance

StandardResultDetails
ECMAScript (TC39 test262, ES2024 scope)40,261 passing, 0 failingof 42,889 tests; 2,628 skipped as ES2025+ or out of scope (details)
HTML5 parsing (html5lib tree construction)364 / 364the 7 html5lib test files the suite runs, of 53
CSS layout (WPT and framework suites, compared with Chrome)1,874 full + 1,403 partial passes of 3,302the 15 gated suites, including Bootstrap 20 / 20 and Tailwind 70 / 70 (details)
CommonMark655 / 655specification examples; GFM tables, task lists and strikethrough add 22 / 22
YAML 1.2 (yaml-test-suite)276 / 276cases with an expected JSON result

Documentation

Language Reference

DocumentDescription
Document PipelineThe Mark data model and the convert/validate/render/view/edit workflows
TutorialTen chapters from installation to a reactive app, with checked examples
CheatsheetQuick reference for syntax and common patterns
Lambda ReferenceLanguage overview, the documentation index, modules, and examples
SyntaxStatements, line continuation, reserved words, symbols, namespaces
Data & CollectionsLiterals, paths, arrays, maps, elements, ranges, document updates
Type SystemTypes, unions, object types, constraints, string patterns
Expressions & StatementsOperators, pipes, queries, control flow, and comprehensions
FunctionsFunction declarations, closures, and procedures
String PatternsThe pattern language inside \(…) and pattern-aware string functions
Reactive UIview/edit templates, apply() and event handlers
Procedural Programmingvar, assignment, value semantics, I/O, main(), concurrency
Error Handlingraise, T^E, postfix ^, the ^ { } handler, error codes
ModulesImports, pub exports, built-in, package and JavaScript modules
ConcurrencyTasks, mailboxes, select, timeouts and cancellation
System FunctionsBuilt-in functions (math, string, collection, I/O, concurrency)
PackagesLibraries written in Lambda that ship with the runtime (math, chart, graph, LaTeX, PDF, …)
CLI ReferenceCommands, flags, and usage for the Lambda CLI
Validator GuideSchema-based validation with lambda validate
Markup & Data Format SupportSupported input and output formats and how they map to Lambda/Mark
Doc SchemaSchema for lightweight markup (Markdown, Wiki, RST)
HTML, CSS and SVG SupportWhat the Radiant layout and rendering engine supports
Math SupportLaTeX and ASCII math input and rendering
Formal SemanticsNormative semantics specification — S-numbered rulings; the semantic authority when docs or implementation disagree

Developer Documentation

DocumentDescription
Developer GuideBuild from source, dependencies, testing, Tree-sitter grammar, MIR JIT
Formal DesignNormative design/implementation specification — D-numbered rulings for the core runtime; the design authority when docs or implementation disagree
Documentation ConventionHow Lambda documentation is organized — document tiers, authority order, and style conventions
C+ Coding ConventionC/C++ coding convention
Lambda Core Runtime DesignDetailed design of the core runtime — compilation pipeline, value & type model, the MIR-Direct transpiler, MIR JIT, memory & GC, builtins, error handling, Mark API, and the procedural runtime
Radiant Engine DesignDetailed design of the HTML/CSS layout, rendering, and interaction engine — view/DOM model, CSS resolution, layout (block/inline/flex/grid/table), rendering pipeline, SVG, events, editing, state, shell, JS scripting, and media/webview (index to the RAD_01–RAD_22 set)
JS and DOM SupportExperimental JavaScript JIT engine and browser DOM — supported features and benchmarks
LambdaJS Runtime DesignDetailed design of the embedded JavaScript engine — compilation pipeline, value model, runtime, standard library, RegExp, async/modules, DOM, and Node.js compatibility

Platform Support

PlatformStatusNotes
macOS✅ FullNative development platform
Linux✅ FullUbuntu 20.04+ tested
Windows✅ FullNative build via MSYS2

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • MIR Project: JIT compilation infrastructure
  • Tree-sitter: Incremental parsing framework
  • ThorVG: SVG vector graphics library
doc-engine
functional-programming
markdown
query-language
reactiveui
schema
template-engine
type-first
validate

henry-luo/lambda

A modern, general-purpose, pure functional programming language (Alpha)

C++

14

7,449 commits

updated Oct 1, 2026

See the code

See what people are saying

README

Lambda Script

License: MIT Platform C++17 Runtime: 20 MB HTML5: 100% CommonMark: 100% YAML 1.2: 100%

A general-purpose, cross-platform, functional scripting language and document processing engine in a single ~20 MB executable, built from scratch in C/C++.

Lambda is designed for two things at once:

  1. an expressive functional language for transforming data and documents, and
  2. an end-to-end document pipeline (parse → validate/transform → layout → render/view).

Lambda and Radiant document pipeline

Internally, Lambda treats documents as structured data. Different input formats (Markdown, Wiki, HTML/XML, JSON/YAML/TOML/CSV, LaTeX, PDF, …) are parsed into a unified Lambda/Mark node tree, transformed with Lambda scripts, validated with schemas, and then rendered via the Radiant HTML/CSS/SVG/JS layout engine.

Note: Lambda Script is still evolving — syntax/semantics and implementation details may change. A stable subset of the literal data model is separately formalised and released as Mark Notation.

Demo

See all supported document types in the demo gallery.

Try it: download the Lambda binary from the Releases page, unzip, and run:

lambda demo

Features

Lambda script (pure functional runtime)

  • Pure-functional core with immutable data structures (arrays, maps, elements) and first-class functions and types.
  • Expressive pipe operator (|>, with the filter stage |:) for fluent set-oriented data transformation pipelines with inline mapping and filtering.
  • Vector arithmetic with automatic broadcasting — apply scalar operations to entire collections.
  • Powerful for-expressions with where, order by, limit, offset clauses for SQL-like data querying.
  • Interactive REPL for exploration and debugging.

Markup input parsing & formatting

  • Multi-format parsing: JSON, XML, HTML, Markdown, Wiki, YAML/TOML/INI, CSV, LaTeX, PDF, and more.
  • One universal representation: parse disparate syntaxes into a common Lambda/Mark node tree.
  • Conversion pipeline: convert between formats using lambda convert (auto-detect input formats when possible).
  • DOM-centric tooling: designed to treat "documents as data/objects", not just as text.

Type system & schema validation

  • Rich type system with type inference and explicit type annotations, similar to and beyond that of TypeScript.
  • Schema-based validation for structured data and document trees (including element schemas for HTML/XML-like structures).

Type Hierarchy

Radiant HTML/CSS/SVG/JS layout, rendering & viewer

  • Browser-compatible layout engine supporting html block, inline, flex, grid, and tables.
  • Unified interactive viewer via lambda view:
    • HTML/CSS/SVG with JavaScript — the embedded LambdaJS engine covers ES2024 (test262), the browser DOM and a Node.js compatibility layer
    • XML (treated as HTML with CSS styling)
    • Markdown / Wiki (rendered with styling)
    • LaTeX (.tex) via conversion to HTML
    • Lambda script (.ls) evaluated to HTML and rendered (think of PHP)
  • Render targets: SVG / PDF / PNG / JPEG output via lambda render.

Language Highlights

Elements (Markup Literals)

First-class markup syntax for document generation:

let card = <div class: "card",
    <h2 "Title">
    <p "Content here.">
>
format(card, 'html')

Vector Arithmetic

Scalar operations automatically broadcast over collections:

1 + [2, 3];          // [3, 4]       — scalar + array
[1, 2] * 2;          // [2, 4]       — array * scalar
[1, 2] + [3, 4];     // [4, 6]       — element-wise
[1, 2] ** 2;         // [1, 4]       — element-wise power
[1, 2, 3] eq 2       // [false, true, false] — element-wise comparison

Pipe Operator & Data Pipelines

The pipe operator |> enables fluent data transformations, and its filter stage |: keeps the items a test accepts. Use ~ to reference the current item:

let users = [{name: "Alice", age: 30}, {name: "Bob", age: 15}, {name: "Carol", age: 41}]

// Map: double each element
[1, 2, 3] |> ~ * 2;                  // [2, 4, 6]

// Extract fields
users |> ~.name;                     // ["Alice", "Bob", "Carol"]

// Filter with '|:'
[1, 2, 3, 4, 5] |: ~ > 3;            // [4, 5]

// Chain operations: filter → map → aggregate
users |: ~.age >= 18 |> ~.name |> len   // 2 — count adult names

For-Expressions with SQL-like Clauses

Powerful comprehensions with let, where, order by,group by, limit, offset:

// Filter and transform
for (x in data where x > 0) x * 2

// With local bindings
for (x in data, let sq = x * x where sq > 10) sq

// Sorting and pagination
for (x in items order by x.price desc limit 5) x.name

Rich Type System

// Type annotations
let x: int = 42
let items: string[] = ["a", "b"]

// Union and optional types
type Result = int | error
type Name = string?

// Element type patterns
type Link = <a href: string; string>
type Article = <article title: string; string, Section*>

// Function types
fn add(a: int, b: int) int => a + b

Pattern-based Matching & Query

Match expressions support value, range, type, and constrained patterns:

fn describe(x) => match x {
    case null:             "nothing"
    case 0:                "zero"              // literal value
    case 1 to 9:           "small number"      // range
    case int that ~ > 9:   "big number"        // type + constraint
    case string:           "text: " ++ ~       // type
    case int[]:            "int array"         // collection type
    default:               "something else"
}

The ? query operator searches data trees by type or structure, similar to jQuery:

html?<img>                    // all <img> descendants
html?<div class: string>      // <div>s with a class attribute
data?{status: "ok"}           // maps where status == "ok"
html[body][div]?<a>           // direct path then recursive search (given type body = <body>, type div = <div>)

Quick Start

Install From Source

  1. Clone the repository:

    git clone https://github.com/henry-luo/lambda.git
    cd lambda
    
  2. Install dependencies:

    ./setup-mac-deps.sh       # macOS
    ./setup-linux-deps.sh     # Linux
    ./setup-windows-deps.sh   # Windows (under MSYS2)
    
  3. Build:

Lambda uses a Premake5-based build system generated from build_lambda_config.json.

make build             # Incremental build (recommended)
make release           # Optimized release build
make test              # Run unit test
make clean-all         # Clean build artifacts

CLI Commands

The build produces lambda.exe at the repo root; release bundles ship it as lambda.

lambda                                          # interactive REPL
lambda <script.ls>                              # run a functional script
lambda run <script.ls>                          # run a procedural script
lambda validate <file> [-s <schema.ls>]         # validate against a schema
lambda convert <input> -t <to> -o <output>      # format conversion
lambda layout <file.html>                       # print the CSS layout tree
lambda render <input> -o <output.svg|pdf|png>   # render to image
lambda view <file.html|file.md|file.ls|...>     # open in interactive viewer
lambda edit <file.md|file.html|file.svg>        # edit a document and save it back
lambda fetch <url> [-o file]                    # download a URL
lambda js <script.js>                           # run JavaScript on LambdaJS
lambda --help                                   # show help

Tip: lambda <command> --help prints detailed options and examples.

Examples

Document Processing

// Parse JSON and convert to Markdown (`^` propagates a read error)
let data = input("data.json", 'json')^
format(data, 'markdown')

// Process CSV data
let csv = input("data.csv", 'csv')^
for (row in csv where row.age > 25) row

Interactive CLI/REPL

λ> let data = input("sample.json", 'json')^
λ> len(data.users)
42
λ> for (u in data.users where u.active) u.name
("Alice", "Bob", "Charlie")

Benchmark Results

Lambda benchmark history

The latest run (Result50, 2026-09-30) covers 63 benchmarks across six standard suites (R7RS, AWFY, BENG, KOSTYA, LARCENY, JetStream) plus Text, against Node.js v22.13.0. Ratios are geometric means of JIT-pinned Lambda execution time divided by Node.js time; below 1.0× means Lambda is faster.

Lambda MIR JIT vs. Node.jsGeo. Mean RatioLambda WinsTotal
Typed0.54× (1.8× faster)4263
Untyped1.05× (5% slower)3263

See the latest full benchmark report for per-benchmark details, memory profiling, and cross-engine comparisons.

Standards Conformance

StandardResultDetails
ECMAScript (TC39 test262, ES2024 scope)40,261 passing, 0 failingof 42,889 tests; 2,628 skipped as ES2025+ or out of scope (details)
HTML5 parsing (html5lib tree construction)364 / 364the 7 html5lib test files the suite runs, of 53
CSS layout (WPT and framework suites, compared with Chrome)1,874 full + 1,403 partial passes of 3,302the 15 gated suites, including Bootstrap 20 / 20 and Tailwind 70 / 70 (details)
CommonMark655 / 655specification examples; GFM tables, task lists and strikethrough add 22 / 22
YAML 1.2 (yaml-test-suite)276 / 276cases with an expected JSON result

Documentation

Language Reference

DocumentDescription
Document PipelineThe Mark data model and the convert/validate/render/view/edit workflows
TutorialTen chapters from installation to a reactive app, with checked examples
CheatsheetQuick reference for syntax and common patterns
Lambda ReferenceLanguage overview, the documentation index, modules, and examples
SyntaxStatements, line continuation, reserved words, symbols, namespaces
Data & CollectionsLiterals, paths, arrays, maps, elements, ranges, document updates
Type SystemTypes, unions, object types, constraints, string patterns
Expressions & StatementsOperators, pipes, queries, control flow, and comprehensions
FunctionsFunction declarations, closures, and procedures
String PatternsThe pattern language inside \(…) and pattern-aware string functions
Reactive UIview/edit templates, apply() and event handlers
Procedural Programmingvar, assignment, value semantics, I/O, main(), concurrency
Error Handlingraise, T^E, postfix ^, the ^ { } handler, error codes
ModulesImports, pub exports, built-in, package and JavaScript modules
ConcurrencyTasks, mailboxes, select, timeouts and cancellation
System FunctionsBuilt-in functions (math, string, collection, I/O, concurrency)
PackagesLibraries written in Lambda that ship with the runtime (math, chart, graph, LaTeX, PDF, …)
CLI ReferenceCommands, flags, and usage for the Lambda CLI
Validator GuideSchema-based validation with lambda validate
Markup & Data Format SupportSupported input and output formats and how they map to Lambda/Mark
Doc SchemaSchema for lightweight markup (Markdown, Wiki, RST)
HTML, CSS and SVG SupportWhat the Radiant layout and rendering engine supports
Math SupportLaTeX and ASCII math input and rendering
Formal SemanticsNormative semantics specification — S-numbered rulings; the semantic authority when docs or implementation disagree

Developer Documentation

DocumentDescription
Developer GuideBuild from source, dependencies, testing, Tree-sitter grammar, MIR JIT
Formal DesignNormative design/implementation specification — D-numbered rulings for the core runtime; the design authority when docs or implementation disagree
Documentation ConventionHow Lambda documentation is organized — document tiers, authority order, and style conventions
C+ Coding ConventionC/C++ coding convention
Lambda Core Runtime DesignDetailed design of the core runtime — compilation pipeline, value & type model, the MIR-Direct transpiler, MIR JIT, memory & GC, builtins, error handling, Mark API, and the procedural runtime
Radiant Engine DesignDetailed design of the HTML/CSS layout, rendering, and interaction engine — view/DOM model, CSS resolution, layout (block/inline/flex/grid/table), rendering pipeline, SVG, events, editing, state, shell, JS scripting, and media/webview (index to the RAD_01–RAD_22 set)
JS and DOM SupportExperimental JavaScript JIT engine and browser DOM — supported features and benchmarks
LambdaJS Runtime DesignDetailed design of the embedded JavaScript engine — compilation pipeline, value model, runtime, standard library, RegExp, async/modules, DOM, and Node.js compatibility

Platform Support

PlatformStatusNotes
macOS✅ FullNative development platform
Linux✅ FullUbuntu 20.04+ tested
Windows✅ FullNative build via MSYS2

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • MIR Project: JIT compilation infrastructure
  • Tree-sitter: Incremental parsing framework
  • ThorVG: SVG vector graphics library
doc-engine
functional-programming
markdown
query-language
reactiveui
schema
template-engine
type-first
validate

Languages

C++

45.9%

C

19.6%

HTML

9.9%

JavaScript

9.6%

LiveScript

6.7%

Python

2.6%

Rust

1.9%